Shell脚本监控WEB服务是否正常
2015-02-01 10:24
736 查看
Step1.安装sendmail来发邮件# yum -y install sendmail# /etc/init.d/sendmail start# chkconfig sendmail onStep2.安装mutt邮件客户端,并设置相关信息# yum -y install mutt# vim /etc/Muttrc set charset="utf-8" #设置发邮件编码 set envelope_from=yes set rfc2047_parameters=yes #解决附件乱码问题 set realname="报警" #发件人别名 set use_from=yes #指定是否显示别名 set from=monitor@test.com #发送人地址Step3.脚本信息
1.url文件如下
# cat url
www.baidu.com
www.sina.com
2.脚本如下
本文出自 “李振良的技术博客” 博客,请务必保留此出处http://lizhenliang.blog.51cto.com/7876557/1610408
1.url文件如下
# cat url
www.baidu.com
www.sina.com
2.脚本如下
#!/bin/bash #==================================================== # Author: lizhenliang - EMail:zhenliang369@163.com # Last modified: 2015-2-1 # Filename: web_mon.sh # Description: wget monitoring web is normal # blog:lizhenliang.blog.51cto.com #==================================================== while true do Mail="baojingtongzhi@163.com" FailCount=0 Retval=0 GetUrlStatus() { for ((i=1;i<=3;i++)) #使用i++判断访问次数,如果wget两次超时则判断网站异常 do wget -T 3 --tries=1 --spider http://${1} >/dev/null 2>&1 #-T超时时间,--tries尝试1次,--spider蜘蛛 [ $? -ne 0 ] && let FailCount+=1; #访问超时时,$?不等于0,则FailCount加1 done if [ $FailCount -gt 1 ];then Retval=1 Date=`date +%F" "%H:%M` echo -e "Date : $Date\nProblem : $url is not running." | mutt -s "URL Monitor" $Mail else Retval=0 fi return $Retval #如果返回值为0,就正常退出循环,不为0则继续循环 } for url in `cat url | sed '/^#/d'` do #GetUrlStatus $url && echo yes || echo no GetUrlStatus $url done sleep 2m #死循环,设置没2分钟运行一次 done
本文出自 “李振良的技术博客” 博客,请务必保留此出处http://lizhenliang.blog.51cto.com/7876557/1610408
相关文章推荐
- shell脚本监控MySQL服务是否正常
- shell脚本:监控MySQL服务是否正常
- shell脚本:监控MySQL服务是否正常
- shell脚本:监控MySQL服务是否正常
- 如何通过shell脚本来检查或监控MYSQL数据库服务是否正常?
- 一个监控WEB服务是否正常的shell
- linux实战(十)----shell监控tomcat服务是否正常----综合运用
- 开发监控Web 服务的Shell脚本
- linux实战(十)----shell监控tomcat服务是否正常----综合运用
- linux Web服务程序监控shell脚本
- shell脚本监控集群FTP是否正常,可上传下载文件
- shell监控MySQL服务是否正常
- Shell整理--检查WEB是否正常脚本(附PHP脚本)
- mysql和nginx服务是否正常监控脚本
- 监控网站是否可以正常打开的Shell脚本分享
- 简单监控网站访问是否正常的shell脚本,邮件报警。网站恢复后继续运行。
- shell监控mysql服务是否正常启动
- 检查web服务是否正常脚本
- 监控网站是否可以正常打开的Shell脚本分享
- [Shell] 简单的自动检查ssh代理是否正常的脚本