unix 下监控oracle日志脚本

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

转载于:http://blog.itpub.net/36779/viewspace-911517/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值