日誌關鍵字監控及郵件報警
阿新 • • 發佈:2018-12-27
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