下面是一个查看Nginx 状态的脚本,如果没有运行,则重启服务,并且自动发邮件到指定的邮箱
###########################
#!/bin/bash
###查看nginx服务是否运行
time="$(date +"%Y%m%d-%H:%M")"
i=`netstat -anpt | grep nginx | awk '{print $4}' | awk -F: '{print $2}' | wc -l`
service="/sbin/service"
if [ $i = 0 ]
then
$service nginx restart
echo "$time nginx service is down .... restart..." >> /usr/local/nginx/logs/error.log
echo "$time nginx service restart ...." > /root/mail.txt
mail -s "$time nginx restart" xxx@xxx.com < /root/mail.txt
fi
############end################
希望能帮到你们!!!
转载于:https://blog.51cto.com/zsyiming/1317299