#!/bin/ksh
######################################################
# alert_log_mail.ksh
# Purpose: email error msg in alert log to DBA
# to use it, run thisscript.ksh instancename or ALL
################################################################################
if [ $# -eq 0 ]
then
echo "Usage: `basename $0` | ALL "
exit
else
OPTION=$*
fi
if [ "$OPTION" = "ALL" -o "$OPTION" = "all" ]
then
DB_LIST=`cat /etc/oratab|grep -v ^#|grep -v agent|grep -v Apach|grep -v ^$|awk -F: '{print $1}'`
else
DB_LIST=$OPTION
fi
export DBLOG=/home/oracle/dba/logs
get_msg(){
FILENAME=$1
MSG=$2
if [ -s ${DBLOG}/$(basename ${FILENAME}).mail ]
then
CKPOINT=`tail -1 ${DBLOG}/$(basename ${FILENAME}).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 -r > ${DBLOG}/$(basename ${FILENAME}).m
sg
}
###########################################################
# Main Program
###########################################################
for db in $DB_LIST
do
if [ -z "`cat /etc/oratab|grep -v ^#|grep -v agent|grep -v Apach|grep -v ^$|awk -F: '{print $1}'|grep $db`" ]
then
echo "there is not db named $db defined in the server"
continue
fi
echo $db
get_msg /oracle/admin/$db/bdump/alert_$db.log "ora-|^Mon |^Tue |^Wed |^Thu |^Fri |^Sat |^Sun "
> $DBLOG/$(basename ${FILENAME}).mail
PRE_FLAG=0
cat ${DBLOG}/$(basename ${FILENAME}).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 == 1 ];then echo $CUR_LINE >> $DBLOG/$(basename ${FILENAME}).mail;fi; PRE_FLAG=$FLAG ;;
1) echo $CUR_LINE >> $DBLOG/$(basename ${FILENAME}).mail; PRE_FLAG=$FLAG ;;
esac
done
if [ -s ${DBLOG}/$(basename ${FILENAME}).mail ]; then tail -r ${DBLOG}/$(basename ${FILENAME}).mail|mailx -s "${db}: Alert log error message
" DBA@MAILSERVER.COM; fi
echo "${FILESIZE}:" >> ${DBLOG}/$(basename ${FILENAME}).mail
rm ${DBLOG}/$(basename ${FILENAME}).msg
done
exit
######################################################
# alert_log_mail.ksh
# Purpose: email error msg in alert log to DBA
# to use it, run thisscript.ksh instancename or ALL
################################################################################
if [ $# -eq 0 ]
then
echo "Usage: `basename $0`
exit
else
OPTION=$*
fi
if [ "$OPTION" = "ALL" -o "$OPTION" = "all" ]
then
DB_LIST=`cat /etc/oratab|grep -v ^#|grep -v agent|grep -v Apach|grep -v ^$|awk -F: '{print $1}'`
else
DB_LIST=$OPTION
fi
export DBLOG=/home/oracle/dba/logs
get_msg(){
FILENAME=$1
MSG=$2
if [ -s ${DBLOG}/$(basename ${FILENAME}).mail ]
then
CKPOINT=`tail -1 ${DBLOG}/$(basename ${FILENAME}).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 -r > ${DBLOG}/$(basename ${FILENAME}).m
sg
}
###########################################################
# Main Program
###########################################################
for db in $DB_LIST
do
if [ -z "`cat /etc/oratab|grep -v ^#|grep -v agent|grep -v Apach|grep -v ^$|awk -F: '{print $1}'|grep $db`" ]
then
echo "there is not db named $db defined in the server"
continue
fi
echo $db
get_msg /oracle/admin/$db/bdump/alert_$db.log "ora-|^Mon |^Tue |^Wed |^Thu |^Fri |^Sat |^Sun "
> $DBLOG/$(basename ${FILENAME}).mail
PRE_FLAG=0
cat ${DBLOG}/$(basename ${FILENAME}).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 == 1 ];then echo $CUR_LINE >> $DBLOG/$(basename ${FILENAME}).mail;fi; PRE_FLAG=$FLAG ;;
1) echo $CUR_LINE >> $DBLOG/$(basename ${FILENAME}).mail; PRE_FLAG=$FLAG ;;
esac
done
if [ -s ${DBLOG}/$(basename ${FILENAME}).mail ]; then tail -r ${DBLOG}/$(basename ${FILENAME}).mail|mailx -s "${db}: Alert log error message
" DBA@MAILSERVER.COM; fi
echo "${FILESIZE}:" >> ${DBLOG}/$(basename ${FILENAME}).mail
rm ${DBLOG}/$(basename ${FILENAME}).msg
done
exit
Comments
Post a Comment