Saturday, September 24, 2011

Script To Check Disk Usage and Send Alert URGENT/WARNING.

[root@ 17_johnson]# cat /usr/bin/DiskUsage

#!/bin/bash


#filesystems="/dev/sda1 /dev/sda2 /dev/sda5"
filesystems="/data /log  /app  /backup  /home  /"

for fs in $filesystems
do

size=`df -k  $fs |grep $fs |awk '{ print  $3 }'`

        if [  $size  -le  2500000 ]  ;then
#                mail -b "URGENT: Low disk space for $fs ($size)"
 echo  "$fs ($size) URGENT" | mail -s "Alert: Disk Usage for Ishy  $fs ($size) " shrikant.lokhande@example.com
               echo "URGENT"
                break
        fi
        if [ $size -le  5000000 ] ;then
#                 mail -b "WARNING: Low disk space for $fs ($size)
   echo  "$fs ($size) WARNING" | mail -s "Alert: Disk Usage for Ishy(LOW)  $fs ($size) " shrikant.lokhande@example.com
               echo "WRANING"
fi
done