SHELL script Monitoring oracle alert Log
Monitor alert Lo
Idea: compare the current last line with the last scanned line according to the alert log line number, which is greater than or equal to the last scanned line from the last scanned line to the last line.
#! / bin/bashscriptHome= `dirname $0`scriptName = `basename $0`logDir = $scriptHome/logs#logfile=$logDir/$scriptName_$ (date "+% Y%m%d"). Loglogfile=$logDir/ora-error.logrunfile=$logDir/run.logalertLogFile=/u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.logip= `ifconfig | sed '2q' | awk-F' [:] +'/ inet/ {print $4} '`oraErrMsg=ORA-mailTo=737735250@qq.comif [!-d $logDir]; then mkdir-p $logDirfiif [!-f $alertLogFile] Then echo "Error: $alertLogFile no such file or directory." Exit 1fitouch $runfilestartLine=$ (cat $runfile) endLine=$ (cat $alertLogFile | wc-l) if ["x$startLine" = = "x"]; then startLine=1else startLine=$ (expr $startLine + 1) fiecho "= getting warning log information." if [$endLine-le $startLine]; then # echo "no error message was scanned." Echo "" exit 0fiecho "= = $(date" +% Y-%m-%d% H:%M:%S ") scan line ${startLine}, ${endLine}..." > > $logfile content= `cat $alertLogFile | sed-n "${startLine}, ${endLine} p" `oraError= `echo "$content" | grep "$oraErrMsg" | tee-a $logfile`if ["x$oraError"! = "x"] Then echo "$oraError" | mutt-s "$(date" +% Y-%m-%d% H:%M:%S ") $ip warning log alert"-b $mailTofiecho $endLine > $runfile
The script automatically scans the specified keyword, which in this case is ORA-, and then simply deploys it to crontab.