Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2450470
  • 博文数量: 540
  • 博客积分: 11289
  • 博客等级: 上将
  • 技术积分: 6160
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-11 20:27
个人简介

潜龙勿用,见龙在田

文章分类

全部博文(540)

文章存档

2018年(2)

2013年(5)

2012年(24)

2011年(104)

2010年(60)

2009年(217)

2008年(128)

分类:

2008-08-15 15:55:33


###########################
#!/bin/sh
#Author: Navy Dai. 2008-8-13
#Last modify: 2008-8-18
####### Variables declare ########
SHELLDIR=/databak/shell/mon503
WGETLOG=$SHELLDIR/wgetlog
RECORDALL=$SHELLDIR/record_all503.log
ONLYERR=$SHELLDIR/wgetlog.503
WGETLISTFILE=$SHELLDIR/wgetlist
SENDFILE=$SHELLDIR/send503err.log
####### Shell begin. ############
mkdir -p $SHELLDIR
for file in "WGETLOG" "RECORDALL" "ONLYERR" "SENDFILE"
do
 if [ ! -e "${!file}" ];then
    eval "touch \$$file"    #This line you can also : touch ${!file}
 else
    continue
 fi
done
if [ ! -e $WGETLISTFILE ];then
   touch $WGETLISTFILE
   echo "" > $WGETLISTFILE
   echo "" >> $WGETLISTFILE
fi
while true
do
 for ((i=1;i<=30;i++))
 do
  wget --delete-after -a $WGETLOG -i $WGETLISTFILE
  sleep 1;
 done
cat $WGETLOG >> $RECORDALL
#第一种判断:如果存在503则发送邮件
#......第一种触发方式感觉不太好,所以这几行代码这里就不写了,有时间再研究下了。采用第二种触发方式使得判断更为简单,并且减小了误判的几率。
#第二种判断:如果503的条目数达到5,则发送邮件
 if [ "`grep "503:" $WGETLOG | wc -l`" -ge 5 ];then
 echo "----------`date +%Y-%m-%d_%H:%M:%S`---------" >> $ONLYERR
 grep 503 $WGETLOG >> $ONLYERR
 sendEmail -f alert@jsharer.com -u JS_ERR_503 -o \
   message-file=$ONLYERR -xu alert@jsharer.com -xp 29019853 \
   -t alarm@jsharer.com -s 210.51.44.184:25
 fi
   cat /dev/null > $WGETLOG
# While $RECORDALL file size is up to 200M,compress it and empty it.
 while [ "`ls -l $WGETLOG |awk '{print $5}'`" -ge "204800000" ]
 do
   DATE=`date -I`
   tar zcf $RECORDALL-$DATE.tar.gz $RECORDALL
   cat /dev/null > $RECORDALL
 done
done
终于解决变量嵌套的问题了。
阅读(1966) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~