Alert Log Monitoring Script

 #-----------------------------------------------------------------------------
# Script Name  : ALERT_LOG_MON.sh
# Author       : Adithya
# Support      : 
# Version      : V1.0
# Oracle       : 11g
# Description  : Sends mail on errors generated in alert log
# Revision History: At end of script.
#-----------------------------------------------------------------------------
#!/bin/ksh
MAIL_DBA=adithya.sirimalla@xyz.com
#-----------------------------------------------------------------------------
# Function   : ReportError
# Description: 
#-----------------------------------------------------------------------------
ReportError()
{
FILENAME=$1
MSG=$2
if [ -s /oracle01/scripts/log/alert/$i.mail ]
then
CKPOINT=`tail -1 /oracle01/scripts/log/alert/$i.mail|awk -F: '{print $1}'`
else
CKPOINT=0
fi
FILESIZE=`cat $FILENAME|wc -l`
if [ $FILESIZE -lt $CKPOINT ]
then 
CKPOINT=0
fi
STARTPOINT=`expr ${CKPOINT} + 1 `
tail +${STARTPOINT} ${FILENAME}|head -$(expr ${FILESIZE} - ${STARTPOINT} + 1)|egrep -i "${MSG}"|tail -5000 > /oracle01/scripts/log/alert/$i.msg
return
} # End of ReportError
#-----------------------------------------------------------------------------
a=`hostname`
echo $a
for i in `grep -v "#" /etc/oratab | grep -v "*" |grep "^[a-zA-Z]"| sort -u |awk -F: '{print  $1}'| grep -v agent`
do
if [ -a /oracle01/app/oracle/diag/rdbms/$i/$i/trace/alert_$i.log ]
then 
PRE_FLAG=0
ReportError /oracle01/app/oracle/diag/rdbms/$i/$i/trace/alert_$i.log "ora-|^Mon |^Tue |^Wed |^Thu |^Fri |^Sat |^Sun "
cat /dev/null > /oracle01/scripts/log/alert/$i.mail
cat /oracle01/scripts/log/alert/$i.msg|while read L
do
CUR_LINE=$L
if echo $CUR_LINE|egrep -i "ora-|error"
then
FLAG=1
else
FLAG=0
fi
case $PRE_FLAG in
0) 
if [ $FLAG -eq 1 ]
then 
echo $CUR_LINE >> /oracle01/scripts/log/alert/$i.mail
fi
PRE_FLAG=$FLAG 
;;
1) 
echo $CUR_LINE >> /oracle01/scripts/log/alert/$i.mail
PRE_FLAG=$FLAG 
;;
esac
done
if [ -s /oracle01/scripts/log/alert/$i.mail ]
then 
cat /oracle01/scripts/log/alert/$i.mail | mail -s "${i}: Alert log Error Message" $MAIL_DBA
fi
echo "${FILESIZE}:" >> /oracle01/scripts/log/alert/$i.mail
rm /oracle01/scripts/log/alert/$i.msg
else
mail -s "${i}: Alert log File Not Found" $MAIL_DBA
fi
done

#-----------------------------------------------------------------------------
# Revision History
#-----------------------------------------------------------------------------
# Revision History 1:
# Author          : Adithya
# Version         : 1
# Date   : 
# Support         : Oracle 11g,12c,19c
# Testing OS      : 
# Script Status   :
# Changes         :
#----------------------------------------------------------------------------

No comments:

Post a Comment