#!/bin/bash
d=`date`
c=`pgrep -l nginx | wc -l`
check_nginx()
{
for ((i=1;i<=5;i++))
do
/usr/local/nginx/sbin/nginx 2> /tmp/nginx.log
if [ $? -eq 0 ]
then
echo "${d}nginx 重启${i}次成功" | mail -s "nginx 进程监控" 383xxxxx@qq.com
break
fi
done
}
while :
do
if [ c -gt 1000 ]
then
check_nginx
if [ $i -eq 5 ]
then
echo "${d}nginx 5次重启失败,请登录服务器处理" | mail -s "nginx 进程监控" 383xxxxxx@qq.com
exit
else
sleep 60
c1=`pgrep -l nginx | wc -l`
if [ c1 -gt 1000 ]
then
echo "${d}nginx重启后进行仍大于1000,请登录服务器处理" | mail -s "nginx 进程监控" 383xxxxx@qq.com
exit
fi
fi
fi
sleep 20
done
原文:https://blog.51cto.com/13667909/2506182