1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#!/bin/bash
scriptHome=`dirname $0`
scriptName=`basename $0`
logDir=$scriptHome/logs
#logfile=$logDir/$scriptName_$(date "+%Y%m%d").log
logfile=$logDir/ora-error.log
runfile=$logDir/run.log
alertLogFile=/u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
ip=`ifconfig | sed '2q' | awk -F '[ :]+' '/inet/{print $4}'`
oraErrMsg=ORA-
mailTo=737735250@qq.com
if [ ! -d $logDir ]; then
mkdir -p $logDir
fi
if [ ! -f $alertLogFile ]; then
echo "Error: $alertLogFile no such file or directory."
exit 1
fi
touch $runfile
startLine=$(cat $runfile)
endLine=$(cat $alertLogFile | wc -l)
if [ "x$startLine" == "x" ]; then
startLine=1
else
startLine=$(expr $startLine + 1)
fi
echo "=== 正在获取警告日志信息..."
if [ $endLine -le $startLine ]; then
#echo "未扫描到错误信息."
echo ""
exit 0
fi
echo "===$(date "+%Y-%m-%d %H:%M:%S") 扫描行${startLine},${endLine}..." >> $logfile
content=`cat $alertLogFile | sed -n "${startLine},${endLine}p"`
oraError=`echo "$content" | grep "$oraErrMsg" | tee -a $logfile`
if [ "x$oraError" != "x" ]; then
echo "$oraError" | mutt -s "$(date "+%Y-%m-%d %H:%M:%S") $ip 警告日志告警" -b $mailTo
fi
echo $endLine > $runfile