ITPub博客

首页 > 数据库 > Oracle > unix 下监控oracle日志脚本

unix 下监控oracle日志脚本

原创 Oracle 作者:cyr1974 时间:2007-04-19 09:55:57 0 删除 编辑
在unix下监控oracle日志,如果发现错误,发送邮件给dba。[@more@]

#!/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博客 ” ,链接:https://blog.itpub.net/36779/viewspace-911517/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-03-16

  • 博文量
    37
  • 访问量
    263722