nginx自动检测是否开启80端口

#!/bin/bash
mail=wqsfree@163.com
if netstat -lntp |grep ‘:80’

then
exit
fi
systemctl restart nginx.service
python mail1.py $mail “check_80” “The 80 port is down.”
n=`pgrep -l nginx|wc -l`
if [ $n -eq 0 ]
then
systemctl restart nginx.service 2> /tmp/nginx_start.err
fi
if [ -s /tmp/nginx_start.err ]
then
python mail1.py $mail “nginx_start_error” “`cat
/tmp/nginx_start.err`”
fi

netstat -lntp |grep “:80” 更准确的查看80端口
pgrep -l nginx|wc -l 查看nginx的pid,并统计
[ $n -eq 0 ] 是否等于0

发表评论