shell監控腳本-監控CDN 首頁

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章