写一个脚本,判断本机的80端口是否开启着,如果开启着什么都不做,如果发现端口不存在,那么重启一下httpd服务,并发邮件通知你自己。脚本写好后,可以每一分钟执行一次,也可以写一个死循环的脚本,30s检测一次。
{{{密码回复可见}}}
{{{密码回复可见}}}
0
#!/bin/bash
while :
do
a=`netstat -lnp|grep 80|awk -F '/' '{print $2}'`
if [ -z $a ]
then
/usr/local/apache2/bin/apachectl restart >/dev/null
echo "httpd is restart"| mail -s "httpd is restart" jishan1984@163.com
fi
sleep 30
done
0
#!/bin/bash
if [ -n `netstat -ltnp|grep 80` ]
then
/etc/init.d/nginx start
echo "nginx status start!" |mail "nginx" 135@163.com
fi
0
#!/bin/bash
mail=aiker@gzedu.ml
while :;do
h=`ss -tl | grep http | awk -F ":::" '{print $2}'`
if [ -z $h ];then
/usr/local/apache/bin/apachectl restart &> /dev/null
echo "http is down and restared" | mail -s "httpd is restart" $mail
fi
sleep 30
done
编辑回复