9_Disk_Utilization_Monitoring_Script_Documentation - Nirvan-Pandey/OCI_DOC GitHub Wiki

Disk Utilization Monitoring Script Documentation

9_1: Overview

This script is designed to monitor the disk utilization of all mounted filesystems on a Unix-like operating system. It retrieves the disk usage statistics, prints them, and highlights any mount points that have a utilization above 85%.

9_2: Features

Human-readable Output: The script uses df -h to provide disk usage information in a human-readable format. High Utilization Warning: It highlights any mount points that have a utilization above 85%. Easy to Use: The script is simple to execute and provides immediate feedback on disk usage.

9_3: Usage

Step1: Make the Script Executable

chmod +x check_disk_usage.sh

This command changes the script's permissions to make it executable.

Step2: Run the Script

./check_disk_usage.sh

This command runs the script.

9_4: Script Breakdown

  1. Retrieve Disk Usage Information
df_output=$(df -h)
  1. Print the Header
echo "$df_output" | head -n 1

This command prints the header line of the df output, which contains the column titles.

  1. Iterate Over Each Line of the Output
echo "$df_output" | tail -n +2 | while read -r line; do

This command skips the header line and iterates over each subsequent line of the df output. 4. Extract and Print Usage Information

usage=$(echo $line | awk '{print $5}' | sed 's/%//')
echo "$line"

These commands extract the usage percentage from the current line and print the entire line. 5. Check for High Utilization

if [ "$usage" -gt 85 ]; then
  echo "Warning: Mount point $(echo $line | awk '{print $6}') is above 85% utilization!"
fi

This conditional statement checks if the usage percentage is greater than 85%. If it is, a warning message is printed, indicating the mount point with high utilization.

9_4: Full Script

# Get the disk usage of all mounts
df_output=$(df -h)

# Print the header
echo "$df_output" | head -n 1

# Iterate over each line of the df output
echo "$df_output" | tail -n +2 | while read -r line; do
  # Extract the usage percentage
  usage=$(echo $line | awk '{print $5}' | sed 's/%//')
  
  # Print the line
  echo "$line"
  
  # Check if the usage is above 85%
  if [ "$usage" -gt 85 ]; then
    echo "Warning: Mount point $(echo $line | awk '{print $6}') is above 85% utilization!"
  fi
done