[Shell] Monitor other host oracle instance alert.log and mail
自己寫的每隔一分鐘檢測其他other hosth上的oracle instance的alert.log檔案是否有錯誤,如果有錯誤,則mail出來。
有很多地方沒有考慮到
以後多加改善
1.other host's script
[mon@oracle source]$ more mon_alert_log
#!/bin/bash
alertlog=/u01/oracle/diag/rdbms/yangxu/yangxu/trace/alert_yangxu.log
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"
cat /dev/null > $logdir/"$file"_tmp
cat /dev/null > $logdir/"$file"_tmp1
if [ -s $firstrow ];then
echo "$datetime no alert log in $file"
rm -rf $logdir/"$file"
exit
fi
if [ -s $lastrow ];then
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
2.local host script
[mon@oracle6 source]$ more mon_remote_alertlog
#!/bin/bash
logdir=/tmp
file=alert_yangxu.log
rm -rf $logdir/"$file"_tmp
rm -rf $logdir/"$file"_tmp1
ssh mon@oracle /home/mon/source/mon_alert_log
scp mon@oracle:$logdir/"$file"_tmp /tmp
scp mon@oracle:$logdir/"$file"_tmp1 /tmp
grepstr="ora-|alter|not|close|open|shutdown"
logfile=/home/mon/log/mon_remote_alertlog.log
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 >> $logfile
cat $logdir/"$file"_tmp | head -`expr $j_end - 1` | tail -$j_row | mutt -s "[YangXu]Oracle Database Alert Log Warning" tolilong@163.com
echo "==============================================================================" >> $logfile
fi
done
#rm -rf $logdir/"$file"_tmp
#rm -rf $logdir/"$file"_tmp1
[mon@oracle6 source]$ crontab -l
###############mon other host oracle alert.log###########
* * * * * /home/mon/source/mon_remote_alert_log >> /home/mon/log/mon_remote_alertlog.log
有很多地方沒有考慮到
以後多加改善
1.other host's script
[mon@oracle source]$ more mon_alert_log
#!/bin/bash
alertlog=/u01/oracle/diag/rdbms/yangxu/yangxu/trace/alert_yangxu.log
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"
cat /dev/null > $logdir/"$file"_tmp
cat /dev/null > $logdir/"$file"_tmp1
if [ -s $firstrow ];then
echo "$datetime no alert log in $file"
rm -rf $logdir/"$file"
exit
fi
if [ -s $lastrow ];then
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
2.local host script
[mon@oracle6 source]$ more mon_remote_alertlog
#!/bin/bash
logdir=/tmp
file=alert_yangxu.log
rm -rf $logdir/"$file"_tmp
rm -rf $logdir/"$file"_tmp1
ssh mon@oracle /home/mon/source/mon_alert_log
scp mon@oracle:$logdir/"$file"_tmp /tmp
scp mon@oracle:$logdir/"$file"_tmp1 /tmp
grepstr="ora-|alter|not|close|open|shutdown"
logfile=/home/mon/log/mon_remote_alertlog.log
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 >> $logfile
cat $logdir/"$file"_tmp | head -`expr $j_end - 1` | tail -$j_row | mutt -s "[YangXu]Oracle Database Alert Log Warning" tolilong@163.com
echo "==============================================================================" >> $logfile
fi
done
#rm -rf $logdir/"$file"_tmp
#rm -rf $logdir/"$file"_tmp1
[mon@oracle6 source]$ crontab -l
###############mon other host oracle alert.log###########
* * * * * /home/mon/source/mon_remote_alert_log >> /home/mon/log/mon_remote_alertlog.log
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2082998/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 9.Monitor other host oracle instance alert.log and mailOracleAI
- [Shell] monitor oracle alert.log file and sendmailOracleAI
- [Shell] monitor oracle database listener & instance statusOracleDatabase
- 8.Monitor oracle alert.log file and sendmailOracleAI
- 7.monitor oracle database listener & instance statusOracleDatabase
- [Shell] monitor filesystem
- [Shell] 自動生成oracle awr report並mail出來OracleAI
- golang mail、shell、cookie、uuidGolangAICookieUI
- [Shell] Linux monitor tablespace usageLinux
- [Shell] Monitor filesystem usage & delete expire filedelete
- oracle send mailOracleAI
- [Shell] monitor cpu&mem收集資料
- [Shell] Linux monitor OS process and DB sessionLinuxSession
- [shell] execute remote Script自動生成oracle awr report並mail出來REMOracleAI
- 【SQL】Oracle SQL monitorSQLOracle
- Oracle database instanceOracleDatabase
- STATUS OF ORACLE INSTANCEOracle
- oracle mail utl_smtpOracleAI
- Oracle Real Time SQL MonitorOracleSQL
- Oracle instance解釋Oracle
- [Developer] Oracle send mail procedure(2)DeveloperOracleAI
- Oracle 11g Health MonitorOracle
- Introduction to an Oracle Instance (284)Oracle
- [Oracle] oracle 11g dataguard (one instance)Oracle
- Other two network issues in the installation of Oracle RAC DBOracle
- Oracle下的Databse,Instance,SchemasOracle
- [Linux] mutt+msmtp傳送mail時出現瞭如下錯誤(msmtp: cannot locate host)LinuxAI
- 【Oracle】-Difference between Instance recovery and Crash RecoveryOracle
- oracle instance and listener自動啟動Oracle
- mailAI
- Oracle10g新增DBMS_MONITOR包Oracle
- oracle 11g health monitor健康監控Oracle
- 【oracle官網】 Restoring a Database on a New HostOracleRESTDatabase
- 【TUNE_ORACLE】等待事件之IO等待“read by other session”Oracle事件Session
- oracle troubleshooting waits for locks/Enqueues other than 'TM','TX' and 'UL'OracleAIENQ
- Oracle Dba必須瞭解的Read By Other Session等待:OracleSession
- Runloop + runtime + otherOOP
- Oracle例項囚籠(Instance Caging)Oracle