监控alert 日志思路:按alert日志行号取当前最后一行和上一次扫描的行对比 大于等于上一次扫描的行 就从上一次扫描的行开始 扫描到最后一行#!/bin/bash scriptHome=`dirname
监控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里即可。
--结束END--
本文标题: SHELL脚本监控oracle alert日志
本文链接: https://www.lsjlt.com/news/39923.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-28
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0