一、下載SendEmail;數據庫
二、創建監控腳本:bash
[oracle@db1 scripts]$ cat check_lsnr_alterlog.sh #!/bin/sh source ~/.bash_profile #定義變量 v_datetime=`date +"%Y-%m-%d %H:%M:%S"` #操做系統用戶名 v_username='oracle' #數據庫名 v_dbname='xxxdb1' #Oracle Sid v_oraclesid='xxxdb11' #發送者郵箱 v_sendmail='' #發送者郵箱用戶名 v_mailname='' #發送者郵箱密碼 v_password='' #smtp服務器IP或域名:smtp.163.com v_smtpserver='113.108.212.80' #接收者郵件,若是是多個用空間分開 v_receivemail=' ' #路徑 v_path="/home/${v_username}/scripts" #Oracle報警日誌文件位置,10g與11g位置不一樣 v_alertlogpath="${ORACLE_BASE}/diag/rdbms/${v_dbname}/${v_oraclesid}/trace" #####Oracle 報警日誌文件監控代碼開始##### if [ -f ${v_alertlogpath}/alert_${v_oraclesid}.log ] ; then cat ${v_alertlogpath}/alert_${v_oraclesid}.log > ${v_path}/alert_work_${v_oraclesid}.log > ${v_alertlogpath}/alert_${v_oraclesid}.log cat ${v_path}/alert_work_${v_oraclesid}.log >> ${v_alertlogpath}/alert_${v_oraclesid}.history grep -E ^ORA-\|Reconfig\|abort\|Shut\|Start\|error\|Instance\|Suspend\|Resuming\|Deadlock ${v_path}/alert_work_${v_oraclesid}.log > ${v_path}/alert_${v_oraclesid}.err fi if [ `cat ${v_path}/alert_${v_oraclesid}.err|wc -l` -gt 0 ] ; then ${v_path}/sendEmail -f ${v_sendmail} -t ${v_receivemail} -s ${v_smtpserver} -u "${v_dbname} ERROR alert_${v_oraclesid}.LOG (${v_datetime})" -xu ${v_mailname} -xp ${v_password} -o message-content-type=text -o message-charset=UTF-8 message-file=${v_path}/alert_work_${v_oraclesid}.log -l ${v_path}/lsnr_alterlog_sendmail.log fi rm -f ${v_path}/alert_${v_oraclesid}.err rm -f ${v_path}/alert_work_${v_oraclesid}.log #####Oracle 報警日誌文件監控代碼結束##### #####Oracle LISTENER 監控代碼開始##### rm -f ${v_path}/lsnr_${v_oraclesid}.exist ps -ef|grep -i LISTENER|grep -v grep > ${v_path}/lsnr_${v_oraclesid}.exist if [ -s ${v_path}/lsnr_${v_oraclesid}.exist ] ;then echo else ${v_path}/sendEmail -f ${v_sendmail} -t ${v_receivemail} -s ${v_smtpserver} -u "${v_oraclesid} LISTENER process down (${v_datetime})" -xu ${v_mailname} -xp ${v_password} -m "Check oracle LISTENER" -l ${v_path}/lsnr_alterlog_sendmail.log fi #####Oracle LISTENER 監控代碼結束#####
三、配置crontab,每一分鐘執行一次
服務器
[oracle@db1 scripts]$ crontab -l #oracle listener and alterlog check */1 * * * * /home/oracle/scripts/check_lsnr_alterlog.sh >/dev/null 2>&1