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