#!/bin/sh web01="http://172.18.52.xx:8080/web/api/getTime" web02="http://172.18.52.xx:8080/web/api/getTime" web01_status="/root/.web01_cache" web02_status="/root/.web02_cache" maillog="/root/maillog" #状态码:0是正常,1是异常 mails="4948xxxx@qq.com,1012xxxx@qq.com" time=`date -d today +"%Y-%m-%d"` #$web01 $web01_status $mails mailing(){ count=`cat $2|grep 1|wc -l` result=`curl -s -m 2 $1 -o /dev/null -w %{http_code}` > /dev/null #echo $result if [ $result -eq 200 ];then if [ $count -gt 2 ];then echo $2 |awk -F. '{print$2}'|awk -F_ '{print$1"节点已经恢复"}'|mail -s "MoGuMiao告警" $3 > /dev/null fi echo 0 > $2 else echo 1 >> $2 fi count=`cat $2|grep 1|wc -l` #echo $count if [ $count -gt 2 ];then echo $2 |awk -F. '{print$2}'|awk -F_ '{print$1"节点故障,请尽快检查"}'|mail -s "MoGuMiao告警" $3 > /dev/null fi } ############################################ #web01检查 mailing $web01 $web01_status $mails #web02检查 mailing $web02 $web02_status $mails