###########################
#!/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
终于解决变量嵌套的问题了。
阅读(2012) | 评论(0) | 转发(0) |