本文共 1724 字,大约阅读时间需要 5 分钟。
#!/bin/bash#auto monitor #write by 2015-8-9IP=ifconfig |grep "Bcast" |awk '{print $2}'|sed 's/addr://g'DATE=`date`EMAIL=email.txtcat << EOF################################################################ wlecome to use auto ################### monitor scripts ###################################################################EOF if [ -z $1 ];then echo -e "\033[32mUsage :{sh $0 nginx|http|mysql|ntp|list.txt}\033[0m" sleep 2 exit fiif [ -f "$1" -a "$1" == "list.txt" ];thenfor i in `cat list.txt`do count=`ps -ef |grep $i|grep -v grep|grep -v "$0"|wc -l`if [ $count -eq 0 ];thencat >$EMAIL << EOF+++++++++++++++++++SERVER MONITOR++++++++++++++++++++++++通知类型:故障服务:$i主机:$IP状态:警告日期:$DATE额外信息:CRITTACL + $i server is no running ,please check..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++EOF echo -e "\033[32mthe monitor $i warning ,please check..\033[0m" mail -s "$IP $i warning" 752840649@qq.com < $EMAIL >>/dev/null 2>&1 else echo -e "\033[32mthe monitor $i is ok...\033[0m" fidoneelse count=`ps -ef |grep $1|grep -v grep|grep -v $0|wc -l` if [ $count -eq 0 ];thencat >$EMAIL << EOF+++++++++++++++++++SERVER MONITOR++++++++++++++++++++++++通知类型:故障服务:$1主机:$IP状态:警告日期:$DATE额外信息:CRITTACL + $1 server is no running ,please check..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++EOF dos2unix $EMAIL echo -e "\033[32mthe monitor $1 warning ,please check..\033[0m" mail -s "$IP $1 warning" 752840649@qq.com < $EMAIL >>/dev/null 2>&1 else echo -e "\033[32mthe monitor $1 is ok...\033[0m" fi fi
转载于:https://blog.51cto.com/woshitieren/1683157