shell监控脚本-监控CDN 首页

简介:

注意:请先参考 shell监控脚本-准备工作,监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试
#监控CDN 首页

 
  1. cat chk_cdn.sh

  2. #!/bin/bash

  3. #

  4. #script_name:chk_cdn.sh

  5. #check cdn index.html

  6. #Domain name resolution

  7. #

  8. #last update 20130320 by dongnan

  9. #bbs# http://bbs.ywwd.net/

  10. #blog# http://dngood.blog.51cto.com

  11. #

  12. #tail error.log  

  13. #curl: (6) name lookup timed out

  14. #variables  

  15. #check_time=2        #检查间隔时间,2s

  16. check_count=8        #故障后检查次数,8次

  17. fault_count=4        #故障次数大于(4次),则认为不可用

  18. www_url="http://www.test.com"

  19. domain=www.test.com

  20. sh_dir=/root/sh/

  21. crondir=${sh_dir}crontab

  22. error_log=${crondir}/log/cdn_error.log

  23. flag_file=${crondir}/log/cdn.flag

  24. echo=/bin/echo

  25. curl=/usr/bin/curl

  26. options='--connect-timeout 3 -IL -A "check_cdn_www"'

  27. source ${sh_dir}/CONFIG

  28. #main

  29. test -e "${crondir}/log" || mkdir -p "${crondir}/log"

  30. #true

  31. if $curl $options $www_url > /dev/null 2>&1 ;then

  32. #flag

  33.    if [ -f $flag_file ];then

  34.        #sms

  35.        #for mobile in $MOBILES; do

  36.            #$echo "cdn_www ok" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode

  37.            #$echo "cdn_www_index.html ok"

  38.        $done

  39.        #email

  40.        for mail in $MAILS;do

  41.            $echo "$domain ok" | mail -s "cdn ok" $mail

  42.        done

  43.        #flag

  44.        test -e "$flag_file" && rm -f "$flag_file"

  45.    fi

  46. #false

  47. else

  48. #flag真退出脚本

  49.    test -e $flag_file && exit 0

  50. check_failed=0

  51.    #

  52.    for((i=1;i<="$check_count";i++));do

  53. check_date=$(date '+ %F %T')

  54.        #curl 值取反

  55.        if ! $curl $options $www_url > /dev/null 2>&1;then

  56.            #变量加1

  57.            ((check_failed++))

  58.            #error.log

  59.            $echo "$(/bin/date +'%F %T') $www_url $check_failed fault" >> "$error_log"

  60.            /usr/bin/dig "$domain" >> "$error_log"

  61.            #

  62.            sleep 1

  63.        fi

  64.    done

  65.    #

  66.    if [ "$check_failed" -gt "$fault_count" ];then

  67.         #sms

  68.         #for mobile in $MOBILES;do

  69.             #$echo "www_cdn_index.html error" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode

  70.             #/bin/date +'%F %T' && $echo "www_cdn_index.html error"

  71.         #done

  72.         #email

  73.         for mail in $MAILS;do

  74.             $echo "$domain error" | mail -s "cdn error" $mail

  75.         done

  76.         #flag

  77.         $echo "cdn_www_index.html error" > "$flag_file"

  78.         #log

  79.    fi

  80. fi

#  
结束
更多请:  
linux 系统运维  37275208  
vmware 虚拟化  166682360


本文转自 dongnan 51CTO博客,原文链接:http://blog.51cto.com/dngood/1163569


相关文章
|
25天前
|
弹性计算 Shell Perl
ecs服务器shell常用脚本练习(二)
【4月更文挑战第1天】shell代码训练(二)
106 1
|
28天前
|
Java Shell
SpringBoot启动脚本Shell
SpringBoot启动脚本Shell
18 0
|
5天前
|
Java 关系型数据库 MySQL
Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
【4月更文挑战第12天】Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
33 3
|
2天前
|
监控 Shell 应用服务中间件
第十二章 Shell脚本编写及常见面试题(二)
第十二章 Shell脚本编写及常见面试题(二)
|
2天前
|
监控 关系型数据库 Shell
第十二章 Shell脚本编写及常见面试题(一)
第十二章 Shell脚本编写及常见面试题(一)
|
2天前
|
监控 Shell
生产环境Shell脚本Ping监控主机是否存活(多种方法)
生产环境Shell脚本Ping监控主机是否存活(多种方法)
|
2天前
|
运维 Shell
Shell脚本判断IP是否合法性(多种方法)
Shell脚本判断IP是否合法性(多种方法)
|
8天前
|
运维 监控 Shell
利用Shell脚本编写局域网监控软件:实时监测主机连接情况
本文介绍了如何使用Shell脚本创建一个局域网监控工具,以实时检查主机连接状态。脚本包括扫描IP地址范围检测主机可达性及使用`netstat`监控ESTABLISHED连接。此外,还展示了如何每60秒将连接数数据自动提交到指定网站API,以便实时跟踪网络活动。这个自动化监控系统有助于提升网络安全性和故障排查效率。
32 0
|
9天前
|
Shell
Shell脚本之流程控制语句
Shell脚本之流程控制语句
|
10天前
|
JSON 运维 监控
训练shell常用脚本练习(三)
【4月更文挑战第14天】shell代码训练(三)
32 1