日志关键字监控及邮件报警

find_error.sh 编写如下:

todayday=$(date +%Y-%m-%d)

thismoment=$(date +"%Y-%m-%d %H")

echo $thismoment

prg=/home/hoho/logs

cd $prg

iserror=`grep '$thismoment'  catalina-${todayday}.out -C20|grep 'java.sql.SQLException: PooledConnection has already been closed'`

if [ ! -n "$iserror" ]; then

  echo "${thismoment} 不用报警" >> $prg/abc.txt

else

  echo "${thismoment} 报警" >> $prg/abc.txt

  echo "${thismoment}:java.sql.SQLException: PooledConnection has already been closed" |mail -s "生产报错" [mail_address]

fi

定时任务设置.每30分钟执行一次查询。crontab -l

*/30 * * * *  /home/hoho/logs/find_error.sh

猜你喜欢

转载自www.cnblogs.com/memery/p/10185990.html