码迷,mamicode.com
首页 > Web开发 > 详细

脚本监控web服务器,工作不正常发邮件提醒

时间:2015-06-26 13:18:46      阅读:429      评论:0      收藏:0      [点我收藏+]

标签:

  1. 背景介绍
    公司有多个web网站,没有配置监控服务,每天都需要定时检查服务器是否工作正常。低效耗时。
  2. 代码片段
    #!/bin/bash
    # Author Jerry.huang (Email:Jerry.huang@easeware.net)
    
    # Check web Server
    
    if [[ -z `curl -I -s "http://www.baidu.com" | grep "200 OK"` ]]; then
    
    echo "www.baidu.com server server is down" | mail -s "www.baidu.com Server Alert" jerry.huang@easeware.net,616043155@qq.com && echo "$(date) www.baidu.com server is down" >> /home/checkServerError.log
    
    else
    echo "$(date) www.baidu.com server is OK" >> /home/webCheckSuccess.log
    
    fi

     

  3. 添加定时任务
    crontab -e
    */10 * * * * /usr/local/sbin/checkServerHealth.sh >/dev/null 2>&1

  4. 发邮件功能请参考我之前的文章:
    http://www.cnblogs.com/Mrhuangrui/p/4589809.html

脚本监控web服务器,工作不正常发邮件提醒

标签:

原文地址:http://www.cnblogs.com/Mrhuangrui/p/4601948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!