标签:监控 alert日志
监控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里即可。
标签:监控 alert日志
原文地址:http://dadaloveyou.blog.51cto.com/703960/1878214