#!/bin/sh
# Script used to check the Oracle Database Server log ,in which search error to send mail to dba
# the script was writen by chenyongrui . Copyright. Do not copy it.
for SID in sid1 sid2 sid3
do
ORACLE_SID=$SID
export ORACLE_SID
echo $ORACLE_SID
#extrace the logfile path of the current instance
LOG_DIR=`sqlplus -silent "/ as sysdba" <
select value from v$spparameter where name like 'background_dump_dest%';
quit;
EOF`
# extract the date of that day
date1=`date +"%b %d"`
echo $date1
cd $LOG_DIR
if [ -f alert_${ORACLE_SID}.log ]
then
echo "find the log file"
#else
#extract linenumber of the log which generated on that day
grep -n "$date1" alert_${ORACLE_SID}.log|cut -f1 -d':'>linenum 2>&1
startline=`sed -n '1p' linenum`
endline=`sed -n '$p' linenum`
#extrace the log which generated on that day
sed -n "${startline},${endline}p" alert_${ORACLE_SID}.log >daylog
#serch the error
grep "ORA" daylog >errorlog
attachment=${LOG_DIR}/errorlog
database=$ORACLE_SID
if [ $? -eq 0 ] 此处可调用oracle发送邮件程序 此处可调用oracle发送邮件程序
then
echo "found error in the log file"
cp errorlog errorlog_$ORACLE_SID
sqlplus "/ as sysdba" <
quit;
EOF2
else
sqlplus "/ as sysdba" <
quit;
EOF3
fi
fi
done
exit 0