Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9256512
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 系统运维

2013-11-27 16:53:23

shell监控脚本-监控CDN 首页
2013-03-27 13:36:43
标签:shell 首页 脚本 监控 cdn
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dngood.blog.51cto.com/446195/1163569
shell监控脚本-监控CDN 首页


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

#script_name:chk_cdn.sh 
#check cdn index.html 
#Domain name resolution 

#last update 20130320 by dongnan 
#bbs#
#blog# http://dngood.blog.51cto.com 

#tail error.log  
#curl: (6) name lookup timed out 
#variables  
#check_time=2        #检查间隔时间,2s 
check_count=8        #故障后检查次数,8次 
fault_count=4        #故障次数大于(4次),则认为不可用 
www_url=""
domain=
sh_dir=/root/sh/ 
crondir=${sh_dir}crontab 
error_log=${crondir}/log/cdn_error.log 
flag_file=${crondir}/log/cdn.flag 
echo=/bin/echo 
curl=/usr/bin/curl 
options='--connect-timeout 3 -IL -A "check_cdn_www"'
source ${sh_dir}/CONFIG 
#main 
test -e "${crondir}/log" || mkdir -p "${crondir}/log" 
#true 
if $curl $options $www_url > /dev/null 2>&1 ;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 "$domain ok" | mail -s "cdn ok" $mail 
        done 
        #flag 
        test -e "$flag_file" && rm -f "$flag_file" 
    fi 
#false 
else 
#flag真退出脚本 
    test -e $flag_file && exit 0 
check_failed=0
    # 
    for((i=1;i<="$check_count";i++));do 
check_date=$(date '+ %F %T') 
        #curl 值取反 
        if ! $curl $options $www_url > /dev/null 2>&1;then 
            #变量加1 
            ((check_failed++)) 
            #error.log 
            $echo "$(/bin/date +'%F %T') $www_url $check_failed fault" >> "$error_log" 
            /usr/bin/dig "$domain" >> "$error_log" 
            # 
            sleep 1 
        fi 
    done 
    # 
    if [ "$check_failed" -gt "$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 
         #email 
         for mail in $MAILS;do 
             $echo "$domain error" | mail -s "cdn error" $mail 
         done 
         #flag 
         $echo "cdn_www_index.html error" > "$flag_file" 
         #log 
    fi 
fi 
#  
结束
更多请:  
linux 系统运维  37275208  
vmware 虚拟化  166682360
本文出自 “dongnan” 博客,请务必保留此出处http://dngood.blog.51cto.com/446195/1163569
阅读(1151) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~