功能:
#Author:kashu
#Date:2013-07-26
#Description:Monitoringharddiskspaceusage.
#checkifthemailisthere
if[!-x/bin/mail];then
yum-yinstallmailx||{echo"mailxinstallationfailed!";exit1;}
fi
log=/tmp/LackOfAvailableSpace.txt
>$log
private_ip="$(ip-4-oadsh`ipro|awk'/default/{print$NF}'`|awk'{print$4}')"
#ifyouwanttousethefollowingcommands,makesurethatthecurlisinstalledcorrectly.
#public_ip="`curl-sifconfig.me2>/dev/null`"
#You'dbetterputyourpublicipaddresshere.
public_ip=61.181.xx.xx
hostname=`uname-n`
#PutyourpersonalE-mailaddresshere.
email_addr=xxx@163.com
#Checkdiskspaceusage
forIin`df|awk'{print$(5)*1}'|sort-nu`;do
if["$I"-gt"89"];then
#Ifthecommandbelowexecutionfailed,itmeansthat/tmppartitionisalreadyfull!
#Soyouwillnotbeabletowriteanydatato/tmpfolder.
if!echo-e"Hostname:$hostname\nPrivateIP:$private_ip\nPublicIP:$public_ip\n">>"$log";then
echo-e'Ohmygosh!\nPartitionisfull!\nTakesomeactionassoonaspossible!\n'|\
mail-s"WARNING,SpaceisFULL.PrivateIP:$private_ipHostname:$hostnamePublicIP:$public_ip""$email_addr"
fi
df-hT>>"$log";date>>"$log";mail-s'WARNING,FreeSpaceistooless!'"$email_addr"<"$log"&&break
fi
done
#Checkinodesusage
foriin`df-i|awk'{print$(NF-1)*1}'|sort-nu`;do
if["$i"-gt"89"];then
echo-e"Hostname:$hostname\nPrivateIP:$private_ip\nPublicIP:$public_ip\n">>"$log"
df-i>>"$log";date>>"$log";mail-s'WARNING,HavingtoofewInodes!'"$email_addr"<"$log"&&break
fi
done
![分区使用率的监控脚本_监控脚本](http://img1.ph.126.net/Zpsu6RJ5AXOYnK84DTwLEQ==/2691182252348465380.png)
![分区使用率的监控脚本_监控脚本_02](http://img2.ph.126.net/MPhrBmOxqZEfWaFRdTvnqg==/1324621240418351525.png)