#!/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" <set pagesize 0 feedback off verify off heading off echo off
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 ]
then
echo "found error in the log file"
cp errorlog errorlog_$ORACLE_SID
sqlplus "/ as sysdba" <
此处可调用oracle发送邮件程序
quit;
EOF2
else
sqlplus "/ as sysdba" <
此处可调用oracle发送邮件程序
quit;
EOF3
fi
fi
done
exit 0
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/36779/viewspace-911517/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/36779/viewspace-911517/