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

时间:2023-03-08 23:58:45
脚本监控web服务器,工作不正常发邮件提醒
  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 is down" | mail -s "www.baidu.com Server Alert" @qq.com,vip_star_hr@.com | echo "$(date) www.baidu.com server is down" >> /home/serverCheck.log else
    echo "$(date) www.baidu.com server is OK" >> /home/serverCheck.log fi
  3. 添加定时任务
    crontab -e
    */10 * * * * /usr/local/sbin/checkServerHealth.sh >/dev/null 2>&1

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