Web Dev
Disk space usage alert script - Linux
The disk space usage script is created to check the disk space usage and send alerts when disk space usage is critical.
#Purpose: Script to check disk space usage and send alert on critical usage.
#Created by: Abhijit Sandhan
#####################################################
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
#echo $output
usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usage -ge 90 ]; then
echo "Running out of space \"$partition ($usage%)\" on $(hostname) as on $(date), please check!" |
mail -s "Alert: partition \"$partition\" almost out of disk space $usage%" email@example.com
fi
done
In the above disk space usage script,
One should modify the partitions wish to monitor as it varies from server to server.
The critical usage value is set to 90% to send alerts. One may modify the usage value as per the requirement.
Hope this helps!