改编自网络:
#!/bin/bash
mail=xxxx@xxx.com;
mailflag="true"
logfile=/root/check/checkdisk.log
#limit is 90
cat /dev/null > $logfile;
#count ,how many disks > 90%;
count=`df | grep -v mnt|grep -c -E \(9[1-9]\%\)\|\(100\%\)`;
if [ $count -gt 0 ];
then
echo "This is a alert for disk usage." >> $logfile
echo "host address:" >> $logfile
ifconfig |grep "inet addr" |grep -v "127.0.0.1" |awk '{print $2}'|awk -F ":" '{print $2}' >> $logfile
echo "disk info:" >> $logfile
df -h >> $logfile
if [ "$mailflag" == "true" ]; then mail -s "disk alert" $mail < $logfile;fi;
fi
注意:
邮件服务要正常,把sendmail装好。
发件地址如xxx.com要能ping到。