shell监控脚本-监控web server
2013-03-27 13:32
369 查看
shell监控脚本-监控web server
注意:请先参考 shell监控脚本-准备工作,监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试
#监控web server
结束
更多请:
linux 系统运维 37275208
vmware 虚拟化 166682360
注意:请先参考 shell监控脚本-准备工作,监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试
#监控web server
cat chk_web.sh #!/bin/bash # #script_name:chk_web.sh #check web server 80 port # #last update 20130320 by dongnan #bbs# http://bbs.ywwd.net/ #blog# http://dngood.blog.51cto.com # #curl -IL http://10.0.100.75/check.html 2>&1 | grep '200' #HTTP/1.1 200 OK #别忘了在你的web服务器创建一个check.html #variables curl=/usr/bin/curl usleep=/bin/usleep echo=/bin/echo sh_dir=/root/sh/ crondir=${sh_dir}crontab check_count=5 #故障后检查次数 fault_count=4 #故障次数大于(等于),则认为不可用 options='--connect-timeout 1 -IL -A "check_www"' source ${sh_dir}CONFIG hosts="$LINUX_WEB_HOSTS" #main test -e "${crondir}/log" || mkdir -p "${crondir}/log" #主循环遍历机器 for HOST in $hosts ;do flag_file=$crondir/log/"$HOST".web log=$crondir/log/web_error.log #curl真 if $curl $options http://"$HOST"/check.html 2>&1 | grep '200' > /dev/null;then #flag真,解除报警 if [ -f $flag_file ];then #sms #for mobile in $MOBILES; do #$echo "cdn_www ok" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode #$echo "cdn_www_index.html ok" #done #email for mail in $MAILS;do echo "$HOST 80 port ok" | mail -s "$HOST 80 port ok" $mail done #delete flag test -e "$flag_file" && rm -f "$flag_file" fi #curl假 else #flag真,跳出循环(已报警) test -e $flag_file && continue check_failed=0 # for((i=1;i<="$check_count";i++));do check_date=$(date '+ %F %T') #curl 值取反 if ! $curl $options http://"$HOST"/check.html 2>&1 | grep '200' > /dev/null;then #变量加1 ((check_failed++)) #error.log $echo "$(/bin/date +'%F %T') $HOST $check_failed fault" >> "$log" #使用微妙或者秒 $usleep 300000 || sleep 1 fi done #大(等)于fault_count发送报警 if [ "$check_failed" -ge "$fault_count" ];then #sms #for mobile in $MOBILES;do #$echo "www_cdn_index.html error" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode #/bin/date +'%F %T' && $echo "www_cdn_index.html error" #done #mail for mail in $MAILS;do echo "$HOST 80 port error" | mail -s "$HOST 80 port error" $mail done #log echo "$check_date $HOST web error" >> $log #flag $echo "cdn_www_index.html error" > "$flag_file" fi #主if结束 fi #主循环结束 done#
结束
更多请:
linux 系统运维 37275208
vmware 虚拟化 166682360
相关文章推荐
- shell脚本-监控web可用性
- shell脚本批量监控Linux server配置文件的更改
- 开发监控Web 服务的Shell脚本
- shell脚本批量监控Linux server配置文件的更改
- shell脚本---web监控脚本系列
- Shell脚本监控WEB服务是否正常
- shell脚本 监控 web服务器状态
- linux Web服务程序监控shell脚本
- [SHELL] WEB页面监控脚本 推荐
- shell脚本-监控系统资源并通过短信报警
- 监控web状态的脚本
- 我常用的主机监控Shell脚本
- 简单shell脚本监控网站页面
- shell自动监控重启Tomcat脚本,每一分钟检查
- 利用shell脚本来监控linux系统的负载与CPU占用情况
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 用shell脚本监控进程是否存在 不存在则启动的实例
- 8个DBA最常用的监控Oracle数据库的常用shell脚本