monitor the disk used
时间:2006-02-26 来源:cnscn2008
#!/bin/sh
#
#Name : df-monitor.sh
#Author : cnscn
#Mail : [email protected]
#Time : 2006-02-27 00:10
#Purpose : monitor the disk free, when the rate of disk used is greater than 85% or another value, then mail you the info
# And you can use wall instead of mail
#
#Usage:
# crontab -e
# */30 * * * * /opt/desktop-softs/df-monitor.sh >/dev/null 2>&1
#
#Result:
# $mail
# Subject: disk free warning
#
# Disk: /dev/hda1 Whole: 12.22G Used: 8.85G UsedRate: 72.38%
#
###################################################################
#the mail subject
subject="disk free warning"
#the mail where to send to
tomail="root@localhost"
#function toSendMail
#Param : the content to mail
function toSendMail()
{
if [ -n "$*" ] ; then
echo -e "$*" | mail -s "$subject" "$tomail" #you can use wall instead of mail
fi
}
#to calculte the rate of the disks used, and when the result is not null ,send the mail
toSendMail $(df | awk '(NR >1 && ($3/$2)>0.85 ) {printf "\"Disk: %s Whole: %-3.2fG Used: %-3.2fG UsedRate: %2.2f%\"\\n",$1,$2/1000000,$3/1000000,$3/$2*100; }')
#
#Name : df-monitor.sh
#Author : cnscn
#Mail : [email protected]
#Time : 2006-02-27 00:10
#Purpose : monitor the disk free, when the rate of disk used is greater than 85% or another value, then mail you the info
# And you can use wall instead of mail
#
#Usage:
# crontab -e
# */30 * * * * /opt/desktop-softs/df-monitor.sh >/dev/null 2>&1
#
#Result:
# Subject: disk free warning
#
# Disk: /dev/hda1 Whole: 12.22G Used: 8.85G UsedRate: 72.38%
#
###################################################################
#the mail subject
subject="disk free warning"
#the mail where to send to
tomail="root@localhost"
#function toSendMail
#Param : the content to mail
function toSendMail()
{
if [ -n "$*" ] ; then
echo -e "$*" | mail -s "$subject" "$tomail" #you can use wall instead of mail
fi
}
#to calculte the rate of the disks used, and when the result is not null ,send the mail
toSendMail $(df | awk '(NR >1 && ($3/$2)>0.85 ) {printf "\"Disk: %s Whole: %-3.2fG Used: %-3.2fG UsedRate: %2.2f%\"\\n",$1,$2/1000000,$3/1000000,$3/$2*100; }')
相关阅读 更多 +