Friday, 10 August 2012

Script which will send you email alert when disk space usage is more than 70%

Script which will send you email alert when disk space usage is more than 70%
===========

The Script which will send you email alert when disk space usage is more than 70%:

#!/bin/bash
usage=`df -h | awk '{print $5}' | sed -e N -e 's/\n/ /' | awk '{print $2}' |
tr -d % -s "\n"`
devnm=`df -h | awk '{print $1}' | sed -e N -e 's/\n/ /' | awk '{print $2}' |
tr -s "\n"`
str="============================="

if [ $usage -ge 70 ]; then
info="Disk usage for $devnm is more than 70% , Current Disk usage is $usage %
"
echo -e "$str\n$info\n$str" |mail -s "Alert: Disk Usage for `hostname` on
`date`" abc@yourdom.com

else
info="Disk Usage is $usage% for $devnm"
# echo -e "$str\n$info\n$str" | mail -s "Alert: Disk Usage for `hostname` on
`date`" abc@yourdom.com
fi

No comments:

Post a comment

Note: only a member of this blog may post a comment.