Below shell script shows "Hard Disk Usage" on your email address on regular basis.
Step:1
Make a file & named "disk-alert" & copy below contents in it.
######################################################################
# set admin email so that you can get email
ADMIN="abc@xyz.com" (Mention Your Mail Id Here)
# set alert level 90% is default (Set Usage Level as per the need)
ALERT=90
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
#echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep" $ADMIN
fi
done
######################################################################
Step:2
Edit "crontab" & make below setting.
crontab -e
59 23 * * * /root/script/diskalert
Save & Exit (:wq)
Step:3
service crond start
service sendmail start
chkconfig crond on
chkconfig sendmail on
Please Note : You can use any other mail service in your network as per the availability.
Conclusion:
This shell script will give you "Disk Usage" output on the mentioned email id on daily basis @ 23 Hrs:59 Minutes
Note: Thanks to "cyberciti.biz" to make such a nice effort to make my post more powerful.
No comments:
Post a Comment