Monitoring Alert logs
Idea: Follow the alert journal line number to the current last row and the previous scan row compared to the last scanned row from the previous scan line to scan to the final 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-[email protected]if [ ! -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 " Not scanned for error messages. " echo " exit 0fiecho " ===$ (date "+%y-%m-%d %h:%m:%s") scan lines ${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 alarms -b $mailTofiecho $endLine > $runfile
The script automatically scans for the specified keyword, where it is specified as ora-, and then only needs to be deployed to crontab.
Shell script monitors Oracle alert logs