shell監控腳本-監控CDN 首頁
注意:請先參考 shell監控腳本-準備工做,監控腳本在 rhel5 下測試正常,其它版本的linux 系統請自行測試
#監控CDN 首頁html
cat chk_cdn.sh linux
#!/bin/bash shell
# bash
#script_name:chk_cdn.sh 運維
#check cdn index.html dom
#Domain name resolution curl
# ide
#last update 20130320 by dongnan 測試
#bbs# http://bbs.ywwd.net/ url
#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="http://www.test.com"
domain=www.test.com
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
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
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