歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> SHELL編程

Linux磁盤空間監控的Shell腳本

EMAIL_TO="[email protected]"
EMAIL_TO_B="[email protected]"
EMAIL_TO_C="[email protected]"
Disk_load=95
a=(`df |awk '{print $(NF-1)}'|sed -e 's/\%/ /'g|grep -v "Mounted"|grep -v "\/"`)
i=0
while [ $i -lt ${#a[@]} ]
do
if [ ${a[i]} -gt ${Disk_load} ]; then
IP_Addr=`/sbin/ifconfig|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p'|head -1`
SendMail="警報,服務器IP: "${IP_Addr}" 硬盤空間已經使用:"${a[i]}%" "
MailTitle="Alarm, the server ip:"${IP_Addr}" hard disk space is used "${a[i]}%""
echo $SendMail | mail -s "$MailTitle" -c ${EMAIL_TO_B} ${EMAIL_TO} -- -f ${EMAIL_TO_C}
fi
i=`expr $i + 1`
done

Copyright © Linux教程網 All Rights Reserved