假设/var/log/a.log是某程序的log文件
他的内容是:
2012-07-27 18:12:17,788 INFO
[com.kmsocial.search.websearch.WeiboPool:229] - Weibo pool
running!
要求写个脚本,如果超过2分钟没有产生新log则发送邮件给admin@localhost.localdomain
- #!/bin/bash
- LOGFILE="/var/log/a.log"
- STARTNUM=`wc -l $LOGFILE`
- mail_to_root(){
- mail -s "weibo pool has some problem" root<<!
- there has no logs in two
- !
- }
- exec 6<"$LOGFILE"
- while :
- do
- NEWNUM=`wc -l $LOGFILE`
- if [ "$STARTNUM"_ = "$NEWNUM"_ ];then
- mail_to_root
- else
- STARTNUM=$NEWNUM
- fi
- while read -u 6 new_log
- do
- if echo "$new_log" | grep -q "Weibo pool running";then
- while read -u 6 tmp
- do
- :
- done
- break
- else
- mail_to_root
- fi
- done
- sleep 120
- done
- exec 6<&-
阅读(172) | 评论(0) | 转发(0) |