监控alert 日志
思路:按alert日志行号取当前最后一行和上一次扫描的行对比 大于等于上一次扫描的行 就从上一次扫描的行开始 扫描到最后一行
#!/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
脚本会自动扫描指定的关键字,在这里指定的是ORA- ,然后只需要部署到crontab里即可。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。