8.Monitor oracle alert.log file and sendmail
自己寫的每隔一分鐘檢測alert.log檔案是否有錯誤,如果有錯誤,則mail出來。
第一次寫,有很多地方沒有考慮到。
以後多加改善
[mon@oracle6 source]$ more mon_alert_log
#!/bin/bash
alertlog=/u01/oracle/diag/rdbms/xxxxxdb/xxxxxdb/trace/alert_xxxxxdb.log #alert file location
datetime=`date +"%Y/%m/%d %H:%M:%S"`
mondate=`date -d "-1min"`
logdir=/tmp
file=`echo ${alertlog##*/}`
daystr=`date +"%d"`
count=1000
grepstr="ora-|alter|not|close|open|shutdown" #錯誤關鍵字
echo $mondate ,,, $file
mondate1=`echo $mondate | awk -F ":" 'BEGIN{OFS=":"}{print $1,$2}'`
mondate1_1=`echo $mondate1 | awk '{print $1,$2}'`
mondate1_2=`echo $mondate1 | awk '{print $4}'`
mondate1=${mondate1_1}" "${daystr}" "${mondate1_2}
echo "mondate1:$mondate1"
mondate2=`date | awk -F ":" 'BEGIN{OFS=":"}{print $1,$2}'`
mondate2_1=`echo $mondate2 | awk '{print $1,$2}'`
mondate2_2=`echo $mondate2 | awk '{print $4}'`
mondate2=${mondate2_1}" "${daystr}" "${mondate2_2}
echo "mondate2:$mondate2"
tail -$count $alertlog > $logdir/"$file"$$
firstrow=`cat $logdir/"$file"$$ | grep -n "" | grep "$mondate1" | head -1 | cut -d ":" -f1`
echo "firstrow:$firstrow"
lastrow=`cat $logdir/"$file"$$ | grep -n "" | grep "$mondate2" | head -1 | cut -d ":" -f1`
echo "lastrow:$lastrow"
if [ -s $firstrow ];then #make sure this time have alert message
echo "$datetime no alert log in $file"
rm -rf $logdir/"$file"$$
exit
fi
if [ -s $lastrow ];then #make sure last is exist
echo "output `expr $count + 1 - $firstrow` to alert.log"
tail -`expr $count + 1 - $firstrow` $logdir/"$file"$$ > $logdir/"$file"$$_tmp
chmod 777 $logdir/"$file"$$_tmp
tmp_rowcount=`expr $count - $firstrow`
else
echo "output1 `expr $lastrow - $firstrow` to alert.log"
tail -`expr $count + 1 - $firstrow` $logdir/"$file"$$ | head -`expr $lastrow - $firstrow` > $logdir/"$file"$$_tmp
chmod 777 $logdir/"$file"$$_tmp
tmp_rowcount=`expr $lastrow - $firstrow`
fi
echo "tmp_rowcount:$tmp_rowcount"
rm -rf $logdir/"$file"$$
cat $logdir/"$file"$$_tmp | grep -n "" | grep "$mondate1" >> $logdir/"$file"$$_tmp1
tmp1_count=`cat $logdir/"$file"$$_tmp1 | wc -l`
for((j=1;j<=$tmp1_count;j++))
do
nextj=`expr $j + 1`
j_start=`cat $logdir/"$file"$$_tmp1 | head -$j | tail -1 | cut -d : -f1`
j_end=`cat $logdir/"$file"$$_tmp1 | head -$nextj | tail -1 | cut -d : -f1`
if [ $j -eq $tmp1_count ];then
j_end=`cat $logdir/"$file"$$_tmp | wc -l`
j_end=`expr $j_end + 1`
fi
j_row=`expr $j_end - $j_start`
headrow=`expr $j_end - 1`
warn_count=`cat $logdir/"$file"$$_tmp | head -$headrow | tail -$j_row | egrep -i "$grepstr" | wc -l`
if [ $warn_count -gt 0 ];then
cat $logdir/"$file"$$_tmp | head -$headrow | tail -$j_row >> /home/mon/log/mon_alert_log.log
cat $logdir/"$file"$$_tmp | head -`expr $j_end - 1` | tail -$j_row | mutt -s "[Oracle6]Oracle Database Alert Log Warning" tolilong@163.com
echo "=============================================================================="
fi
done
rm -rf $logdir/"$file"$$_tmp
rm -rf $logdir/"$file"$$_tmp1
新增crontab定時任務,一分鐘執行一次
[mon@oracle6 source]$ crontab -l
###############mon oracle alert.log###########
* * * * * /home/mon/source/mon_alert_log >> /home/mon/log/mon_alertlog.log
第一次寫,有很多地方沒有考慮到。
以後多加改善
[mon@oracle6 source]$ more mon_alert_log
#!/bin/bash
alertlog=/u01/oracle/diag/rdbms/xxxxxdb/xxxxxdb/trace/alert_xxxxxdb.log #alert file location
datetime=`date +"%Y/%m/%d %H:%M:%S"`
mondate=`date -d "-1min"`
logdir=/tmp
file=`echo ${alertlog##*/}`
daystr=`date +"%d"`
count=1000
grepstr="ora-|alter|not|close|open|shutdown" #錯誤關鍵字
echo $mondate ,,, $file
mondate1=`echo $mondate | awk -F ":" 'BEGIN{OFS=":"}{print $1,$2}'`
mondate1_1=`echo $mondate1 | awk '{print $1,$2}'`
mondate1_2=`echo $mondate1 | awk '{print $4}'`
mondate1=${mondate1_1}" "${daystr}" "${mondate1_2}
echo "mondate1:$mondate1"
mondate2=`date | awk -F ":" 'BEGIN{OFS=":"}{print $1,$2}'`
mondate2_1=`echo $mondate2 | awk '{print $1,$2}'`
mondate2_2=`echo $mondate2 | awk '{print $4}'`
mondate2=${mondate2_1}" "${daystr}" "${mondate2_2}
echo "mondate2:$mondate2"
tail -$count $alertlog > $logdir/"$file"$$
firstrow=`cat $logdir/"$file"$$ | grep -n "" | grep "$mondate1" | head -1 | cut -d ":" -f1`
echo "firstrow:$firstrow"
lastrow=`cat $logdir/"$file"$$ | grep -n "" | grep "$mondate2" | head -1 | cut -d ":" -f1`
echo "lastrow:$lastrow"
if [ -s $firstrow ];then #make sure this time have alert message
echo "$datetime no alert log in $file"
rm -rf $logdir/"$file"$$
exit
fi
if [ -s $lastrow ];then #make sure last is exist
echo "output `expr $count + 1 - $firstrow` to alert.log"
tail -`expr $count + 1 - $firstrow` $logdir/"$file"$$ > $logdir/"$file"$$_tmp
chmod 777 $logdir/"$file"$$_tmp
tmp_rowcount=`expr $count - $firstrow`
else
echo "output1 `expr $lastrow - $firstrow` to alert.log"
tail -`expr $count + 1 - $firstrow` $logdir/"$file"$$ | head -`expr $lastrow - $firstrow` > $logdir/"$file"$$_tmp
chmod 777 $logdir/"$file"$$_tmp
tmp_rowcount=`expr $lastrow - $firstrow`
fi
echo "tmp_rowcount:$tmp_rowcount"
rm -rf $logdir/"$file"$$
cat $logdir/"$file"$$_tmp | grep -n "" | grep "$mondate1" >> $logdir/"$file"$$_tmp1
tmp1_count=`cat $logdir/"$file"$$_tmp1 | wc -l`
for((j=1;j<=$tmp1_count;j++))
do
nextj=`expr $j + 1`
j_start=`cat $logdir/"$file"$$_tmp1 | head -$j | tail -1 | cut -d : -f1`
j_end=`cat $logdir/"$file"$$_tmp1 | head -$nextj | tail -1 | cut -d : -f1`
if [ $j -eq $tmp1_count ];then
j_end=`cat $logdir/"$file"$$_tmp | wc -l`
j_end=`expr $j_end + 1`
fi
j_row=`expr $j_end - $j_start`
headrow=`expr $j_end - 1`
warn_count=`cat $logdir/"$file"$$_tmp | head -$headrow | tail -$j_row | egrep -i "$grepstr" | wc -l`
if [ $warn_count -gt 0 ];then
cat $logdir/"$file"$$_tmp | head -$headrow | tail -$j_row >> /home/mon/log/mon_alert_log.log
cat $logdir/"$file"$$_tmp | head -`expr $j_end - 1` | tail -$j_row | mutt -s "[Oracle6]Oracle Database Alert Log Warning" tolilong@163.com
echo "=============================================================================="
fi
done
rm -rf $logdir/"$file"$$_tmp
rm -rf $logdir/"$file"$$_tmp1
新增crontab定時任務,一分鐘執行一次
[mon@oracle6 source]$ crontab -l
###############mon oracle alert.log###########
* * * * * /home/mon/source/mon_alert_log >> /home/mon/log/mon_alertlog.log
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2074311/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [Shell] monitor oracle alert.log file and sendmailOracleAI
- [Developer] Oracle sendmail procedure(1)(轉載)DeveloperOracleAI
- [Shell] Monitor other host oracle instance alert.log and mailOracleAI
- 9.Monitor other host oracle instance alert.log and mailOracleAI
- sendmail配置AI
- sendmail settingAI
- oracle is not in the sudoers fileOracle
- Oracle ASM File DirectoryOracleASM
- oracle utl_fileOracle
- Oracle EBS ATTACHMENT with fileOracle
- OMF (Oracle Managed File)Oracle
- Oracle Password File 理解Oracle
- Sendmail relay規則及配置檔案用法彙總 sendmail配置 (轉)AI
- 熟練使用alert.log日誌
- 安裝和配置sendmailAI
- ebs12 sendmail配置AI
- oracle query output in excel fileOracleExcel
- Oracle Dump Redo Log FileOracle
- linux下關閉sendmailLinuxAI
- [Linux] mutt+msmtp sendmailLinuxAI
- REDHAT 7.1 sendmail配置FAQ (轉)RedhatAI
- Oracle:db file scattered readOracle
- Oracle ASM Cluster File Systems (ACOracleASM
- [Oracle Script] check File I/OOracle
- Oracle ACFS ( ASM Cluster File System )OracleASM
- Oracle alert.log:network interface with IP address xxxx no longer operationalOracle
- 打補丁報錯 File in patch is not a known Oracle Applications fileOracleAPP
- sendmail出現"MXlistforhostnamepointsbacktohostname"問(轉)AI
- 2Gb - File limits in Oracle(轉)MITOracle
- oracle監聽開啟trace fileOracle
- Oracle之 等待事件log file sync + log file parallel write (awr優化)Oracle事件Parallel優化
- Oracle db file parallel write 和 log file parallel write 等待事件 說明OracleParallel事件
- Linux下的sendmail簡介(轉)LinuxAI
- Oracle - UTL_FILE包之詳解Oracle
- Oracle ASM How many allocation units per fileOracleASM
- Unload data to a flat file from Oracle databaseOracleDatabase
- oracle重建control file的操作Oracle
- Oracle EBS log file (R12.1.3)Oracle