Disk Usage Check Script - CloudDarsh/OracleCloud GitHub Wiki
Disk Usage Check Script
Introduction
This document provides an overview and explanation of a bash script designed to check disk usage on a system. The script filters and displays the mount points where the disk utilization is greater than 85%.
Purpose
The purpose of this script is to help system administrators monitor disk usage and identify mount points that are heavily utilized. This can be useful for proactive maintenance and avoiding potential disk space issues.
How It Works
The script uses the df -h command to get the disk usage information in a human-readable format. It then uses awk to filter out the lines where the utilization percentage is greater than 85% and prints those lines in red color for better visibility.
Detailed Explanation Shebang Line:
#!/bin/bash
This line indicates that the script should be run using the Bash shell.
Disk Usage Command: df -h
The df command reports the disk space usage of file systems.
The -h option makes the output human-readable, showing sizes in KB, MB, GB, etc.
Separation Line: echo "*****"
This line prints a line of asterisks to separate the sections of the output for better readability.
AWK Command: df -h | awk '$5+0 > 85 {print "\033[31m" $0 "\033[0m\n"}'
-
-
awkis a powerful text-processing language.
-
-
-
- `` refers to the fifth column of the input, which is the "Use%" column in the df -h output.
-
-
-
+0converts the percentage value to a number (removes the % sign).
-
-
-
> 85checks if the value is greater than 85.
-
-
-
{print "\033[31m" "\033[0m\n"}prints the entire line in red color if the condition is true and adds a blank line after each result.
-
Usage
To use this script, save it to a file (e.g., check_disk_usage.sh) and run it using the following command:
bash check_disk_usage.sh
Script
`!/bin/bash
Display the disk usage in human-readable format df -h
Print a line of asterisks for separation echo "*******************************************************"
Get the disk usage in human-readable format Filter out the lines where the utilization percentage is greater than 85% Print the filtered lines in red color and add a blank line after each result df -h | awk '$5+0 > 85 {print "\033[31m" $0 "\033[0m\n"}'`