File System Usage Monitoring Shell Script

File System Usage Monitoring Shell Script . This script is written using df command and it will send an email alert when your file system usage exceeds mentioned threshold. All disk partition utilization monitoring can be done using below shell script.

Environment: Script will work in all the Unix / Linux environments. Tested in RHEL 5/6/7 and Centos All Versions

Warranty: This shell script does not have WARRANTY. Comes with an no warranty. Execution of this script in any of your environments, we are not responsible for any data loss.

Note: Please test the script before you deploy to the production Environment.

Prerequisites: Before executing the script please verify below commands are working and mail relay agent should work.

# df -hP
# awk
# mail -s "Testing Email" YOUREMAIL-ADDRESS

File System Usage Monitoring Shell Script

#Purpose: Monitoring Disk Space Utilization and Send Email Alert
#Created Date: Wed Jun 6 22:38:01 IST 2018
#Modified Date:
#Author: Ankam Ravi Kumar

for path in `/bin/df -h | grep -vE 'Filesystem|tmpfs' | awk '{print $5}' |sed 's/%//g'`
 if [ $path -ge $THRESHOULD ]; then
 df -h | grep $path% >> /tmp/temp

VALUE=`cat /tmp/temp | wc -l`
 if [ $VALUE -ge 1 ]; then
 mail -s "$HOSTNAME Disk Usage is Critical" $mailto < /tmp/temp

rm -rf /tmp/temp
echo "Thanks for Using Script, Please Visit and write your feedback"
## END Script ###

copy the above shell script code and do as mentioned below steps


Paste the shell script 

:wq <<-- Save & Exit

Set the execution permissions

#chmod +x

Execute the script as mentioned below


If your script execution is successful then schedule to execute the shell script every 5 minutes OR every 30 minutes.

Edit the crontab entries

#crontab -e
# File System Usage Monitoring Using Below Shell Script
*/5 * * * * sh /SCRIPT-PATH/

:wq   << -- Save & Exit

Verify the crontab entry

# crontab -l

That’s about this script. Script is successfully scheduled in your environment. Whenever Disk space utilization more than specified threshold it will send an email alert.

Your Feedback is valuable to us. Please provide your valuable comments…

Disk Space Utilization Monitoring and send email alert

How to Increase XFS File System size

CPU Usage Monitoring

Video Tutorial

Thanks for your wonderful Support and Encouragement