Script to check the diskusage of the server and send email to root@hostname when the usage exceeded 95%

                  Save the following code in a file and execute. I hope this script will give you an idea on some tricks with the 'grep' , 'cut' and 'awk'.
Just know that  We'll use only on the print function of awk.

# set alert level 90% is default
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
used=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
    if [ $used -ge $ALERT ]; then
         echo "Running out of space \"$partition ($used%)\" on $hname as on $date" |
         mail -s "Alert: Almost out of disk space $used" $ADMIN;

This entry was posted by Unknown. Bookmark the permalink.