shell-008:检测502

检测502的方法有多种

1.curl他的状态码(不建议,会对网站造成不必要的访问和多余的日志输出)

2.可以直接检测访问日志

下面用while做成一个死循环监控日志502的状态

#!/bin/bash
while :
do

log=/data/log/nginx/access.log
502_n=`tail -n 300 $log |grep -c ' 502 '`
if [ -z "$502_n" ]
then
exit
fi

if [ $502_n -gt 100 ]
then
/etc/init.d/php-fpm restart >/dev/null 2>/tmp/php-fpm.err
# 此处还可以判断一下php-fpm服务有没有起来。如果启动不成功则发送邮件
php-fpm=`pgrep -l php-fpm |wc -l`
if [ $fpm-fpm -eq 0 ]
then
python mail.py xxx@gmail.com "主题" "内容"
fi
fi


sleep
done

写死循环,在执行的脚本下用上while(如下图所示)

 

posted on 2019-04-29 03:39  yeyu1314  阅读(191)  评论(0编辑  收藏  举报