cpu,内存和disk使用报警脚本
第一次,先來(lái)個(gè)小點(diǎn)心
#!/bin/bash
#Get the system targetuseage(cpu,memory,disk)
dug=`df -hT|grep "/$"|awk '{print$6}'|awk -F% '{print $1}'`
cug=$(expr 100 - $(mpstat|tail -1 |awk'{print $10}'|awk -F. '{print $1}'))
mug=$(expr $(free |grep"cache:"|awk '{print $3}') \* 100 / $(free |grep "Mem"|awk'{print $2}'))
####################
ALOG="/tmp/alter.txt"
AMAIL="laoni@nht.com"
##Judge whether or not record the alter
if [ $dug -gt 90 ]
???????then
??????????????? echo "the diskuseage:$dug%">>$ALOG
fi
#################
if [ $cug -gt 80 ]
???????then
??????????????? echo "the useage of cpu is$cug%">>$ALOG
fi
#########################
if [ $mug -gt 90 ]
???????then
??????????????? echo "the useage of memoryis $mug%">>$ALOG
fi
###################
if [ -f $ALOG ]
???????then
??????????????? cat $ALOG|mail -s "hostalert" $AMAIL
??????????????? rm -rf $ALOG
fi
~
創(chuàng)建crontab計(jì)劃任務(wù)
#service crond status
#crontab -e
*/30 * * * * /root/sysmon.sh
轉(zhuǎn)載于:https://blog.51cto.com/niming2008/1424654
總結(jié)
以上是生活随笔為你收集整理的cpu,内存和disk使用报警脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: UILabel常用属性
- 下一篇: C++ union 公共体