脚本实现功能: 当MWM进程数量大于2并且占用CPU时间超过100时发送邮件报警,脚本如下:
#!/usr/bin/ksh #---------------------------------------------------------------# # Script Name : MWM Check Shell # Version : 3 # Created by : Xin23 # on : 2015.02.04 # Updated by : Xin23 # on : 2015.02.15 # Updated by : Xin23 # on : 2015.02.25 #---------------------------------------------------------------# # Define Directory MWMCHECKDIR=/home/monitor/MWM_Check_Dir cd $MWMCHECKDIR # Define Mail Address List MAILLIST="xxx@xxx.com" HOSTNAME=$(hostname) # Define Mail Title SUBJECT="[$HOSTNAME] MWM Process Warning" # Define Mail Message MWMPROCESSNUM=$(ps -ef | grep mwm | grep -v grep | wc -l| awk ‘{print $1}‘) typeset -i MWM_CPU_TIME="$(ps -ef | grep mwm | grep -v grep | awk ‘{print $8}‘ | grep -Ev ‘xinit|mwm‘ | cut -d ‘:‘ -f 1 | tr ‘\n‘ ‘+‘)0" GenerateMailMessage(){ cat <<EOF >> MAILMESSAGE Subject: $SUBJECT To: "$HOSTNAME Administrator" <xxx@xxx.com> From: "$HOSTNAME Crontab" <xxx@xxx.com> Reply-To: $MAILLIST Dear Customer : 服务器当前时间: $(date) MWM当前进程数为[$MWMPROCESSNUM],占用的CPU时间片为[$MWM_CPU_TIME],请关注,具体如下: $(ps -ef | grep mwm | grep -v grep) 以上 EOF sendmail "$MAILLIST" < MAILMESSAGE rm -f MAILMESSAGE } # Main if [ "$MWMPROCESSNUM" -gt "2" ] && [ "$MWM_CPU_TIME" -gt "100" ] then GenerateMailMessage fi
效果图如下:
THE END
本文出自 “Xin23的流水账” 博客,谢绝转载!
原文地址:http://xin23.blog.51cto.com/1827266/1615873