shell监控网站是否自动运行并自动重启【原创】

shell监控网站是否自动运行并自动重启

#!/bin/bash
wget --spider -q -o /dev/null --tries=1 -T 5 www.baidu.com
if [ $? -eq 0 ];then
  echo "`date` 网站访问正常!" >> /root/web_monitor.log
else
  echo "`date` 网站访问异常!重启服务" >> /root/web_monitor.log
  #重启服务脚本   
sh /root/restart.sh   if [ $? -eq 0 ];then     echo "`date` 重启服务成功" >> /root/web_monitor.log   else     echo "`date` 重启服务失败" >> /root/web_monitor.log     exit   fi fi

也可以使用curl监控网页返回代码

curl -o /dev/null --retry 3 --retry-max-time 8 -s -w %{http_code} www.baidu.com

原文地址:https://www.cnblogs.com/paul8339/p/7843535.html