#!/bin/ksh
#-----------------------------------------------------------------------
#  ROGRAM: CheckAlertLog.ksh
# USAGE: CheckAlertLog.ksh
# FUNCTION: Checks ORACLE Alert logs and pages in case of
# any new errors. SID is Oracle database identifier.
# CALLED BY: cron
#
# CASCADE FILES: $LIBDIR/pagers.txt $LIBDIR/dbinfo.txt $LIBDIR/oraErrCount_${SID}
# AUTHOR Naresh  uri
# Date Thu Jun 1 18:01:56  DT 2000
#-----------------------------------------------------------------------
SID=app1 # Oracle database identifier
ALERTDIR=/opt/oracle8i/admin/oracle/bdump # Directory where Oracle alert file resides
FILE=alert_${SID}.log # Oracle alert file name
MAILX=/usr/bin/mailx # UNIX Mail Program
LIBDIR=${HOME}/zlx_scripts # Directory where useful information is saved
LASTCOUNT=`cat $LIBDIR/oraErrCount_${SID}` # Count of ORA- errors
# detected during last program run
DBINFO=`cat $LIBDIR/dbinfo.txt`
export MAILX
export LIBDIR
export ALERTDIR
sendAlertMessage()
{
MESSAGE="**ALARM** {SID} from ${DBINFO}:`grep "ORA-" $ALERTDIR/$FILE | tail -1 | head -1`"
for LIST in `egrep "DBA" $LIBDIR/pagers.txt`
do
EMAIL=`echo $LIST | awk -F: '{ print $2 }'`
echo $MESSAGE | $MAILX -s "${DBINFO}:alert_log MESSAGE" ${EMAIL}
done
}
probeAlertLog()
{
# Count all Oracle errors - search for string "ORA-"
CheckError=`grep "ORA-" $ALERTDIR/$FILE | wc -l`
# keep a count of current errors present in the Alert file
echo $CheckError > $LIBDIR/oraErrCount_${SID}
# If new errors are detected mail DBA only the last ORA-error Twice
if [ $CheckError -ne $LASTCOUNT ]
then
sendAlertMessage;
sendAlertMessage;
fi
}
probeAlertLog;
echo Successful completion $0 at `date`.
--------------------------
这个程序调用两个文件,
一个是 dbinfo.txt
定义你的数据库。
61.222.44.67_app1(search)
另一个是pagers.txt
zlx:zlx@chinaunix.net BA
zlx:peng@chinaunix.net BA
|
|