您好,登錄后才能下訂單哦!
小編給大家分享一下SHELL腳本如何檢查Oracle DG備庫(kù)是否已經(jīng)應(yīng)用歸檔,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
自動(dòng)檢查Oracle DG備庫(kù)是否已經(jīng)應(yīng)用歸檔的shell腳本:
PS:本腳本需要先創(chuàng)建table:ARC_NOT_REPLY_LOG,這個(gè)表是用來(lái)存放記錄的,如果不需要存放記錄的話,可以將shell腳本的insert刪掉。
ARC_NOT_REPLY_LOG 創(chuàng)建腳本:
CREATE TABLE ORAM.ARC_NOT_REPLY_LOG ( HOSTNAME VARCHAR2(50 BYTE), NAME VARCHAR2(100 BYTE), SEQUENCE NUMBER, APPLIED VARCHAR2(3 BYTE), COMPLETION_TIME VARCHAR2(50 BYTE), ADD_TIME DATE DEFAULT SYSDATE )
shell腳本內(nèi)容:
#!/bin/bash #by Dbabc.net 2012/02/02 #User specific environment and startup programs # if [ -f ~/.bash_profile ]; then . ~/.bash_profile fi export DBAEMAIL=dbabc@dbabc.net export ORACLE_SID=dbabc export IP='10.8.8.1' export SMTP='smtp.dbabc.net' export FRUSER='dba@dbabc.net' export BCCUSER='dba@dbabc.net' export USERPWD='pwd' VALUE=`$ORACLE_HOME/bin/sqlplus -S /nolog <<EOF set heading off feedback off pagesize 0 verify off echo off numwidth 4 connect / as sysdba select count(*) from v\\$archived_log where applied='NO'; exit EOF` if [ "$VALUE" -gt 0 ]; then $ORACLE_HOME/bin/sqlplus -S /nolog > arc_not_reply.log <<EOF set heading off feedback off pagesize 0 verify off echo off set lines 200 col name format a60 connect / as sysdba alter session set nls_date_format='YYYY-MM-DDHH24:MI:SS'; select '$IP',name,sequence#,applied,completion_time from v\$archived_log where applied='NO'; exit EOF cat arc_not_reply.log|rev|awk {'print $1" "$2" "$3" "$4" "$5'} | rev |awk {'print "insert into ARC_NOT_REPLY_LOG(hostname,name,SEQUENCE,applied,COMPLETION_TIME) values(#"$1"#,#"$2"#,"$3",#"$4"#,#"$5"#);"'} |grep -v '##' | grep -v '#on#' | sed "s/#/'/g" |sed "s/%//g"| sed "s/ip/"${v_hostip}"/g" >ARC_NOT_REPLY_LOG.sql; #echo "insert into ARC_NOT_REPLY_LOG(hostname,name,SEQUENCE#,applied,COMPLETION_TIME) values ( '${INTV1}', '${INTV2},'${INTV3}', '${INTV4}', '${INTV5}');" >ARC_NOT_REPLY_LOG.sql; $ORACLE_HOME/bin/sqlplus /nolog <<EOF connect oram/oram@10.8.8.4:1521/yqpt @ARC_NOT_REPLY_LOG.sql commit; exit; EOF /usr/local/bin/sendEmail -f $FRUSER -t ${DBAEMAIL} -bcc $BCCUSER -s $SMTP -u "$IP arclog not reply" -o message-file=arc_not_reply.log -xu "$FRUSER" -xp "$USERPWD" exit else echo `date +'%F %T'`" All the archive log have replyed" >arc_replyok.txt /usr/local/bin/sendEmail -f $FRUSER -t ${DBAEMAIL} -bcc $BCCUSER -s $SMTP -u "$IP arc_replyok" -o message-file=arc_replyok.txt -xu "$FRUSER" -xp "$USERPWD" fi exit
修改其中的變量即可,<< 修改成半角格式,wordpress會(huì)自動(dòng)轉(zhuǎn)換半角的<<。
然后再通過(guò)crontab定時(shí)運(yùn)行此腳本,實(shí)現(xiàn)Email預(yù)警。
實(shí)際上需要修改的地方有以下標(biāo)紅部分:
#!/bin/bash
#by Dbabc.net 2012/02/02
#User specific environment and startup programs
#
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
export DBAEMAIL=dbabc@dbabc.net
export ORACLE_SID=dbabc
export IP='10.8.8.1'
export SMTP='smtp.dbabc.net'
export FRUSER='dba@dbabc.net'
export BCCUSER='dba@dbabc.net'
export USERPWD='pwd'
VALUE=`$ORACLE_HOME/bin/sqlplus -S /nolog <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
connect / as sysdba
select count(*) from v\\$archived_log where applied='NO';
exit
EOF`
if [ "$VALUE" -gt 0 ]; then
$ORACLE_HOME/bin/sqlplus -S /nolog > arc_not_reply.log <<EOF
set heading off feedback off pagesize 0 verify off echo off
set lines 200
col name format a60
connect / as sysdba
alter session set nls_date_format='YYYY-MM-DDHH24:MI:SS';
select '$IP',name,sequence#,applied,completion_time from v\$archived_log where applied='NO';
exit
EOF
cat arc_not_reply.log|rev|awk {'print $1" "$2" "$3" "$4" "$5'} | rev |awk {'print "insert into ARC_NOT_REPLY_LOG(hostname,name,SEQUENCE,applied,COMPLETION_TIME) values(#"$1"#,#"$2"#,"$3",#"$4"#,#"$5"#);"'} |grep -v '##' | grep -v '#on#' | sed "s/#/'/g" |sed "s/%//g"| sed "s/ip/"${v_hostip}"/g" >ARC_NOT_REPLY_LOG.sql;
#echo "insert into ARC_NOT_REPLY_LOG(hostname,name,SEQUENCE#,applied,COMPLETION_TIME) values ( '${INTV1}', '${INTV2},'${INTV3}', '${INTV4}', '${INTV5}');" >ARC_NOT_REPLY_LOG.sql;
$ORACLE_HOME/bin/sqlplus /nolog <<EOF
connect oram/oram@10.8.8.4:1521/yqpt
@ARC_NOT_REPLY_LOG.sql
commit;
exit;
EOF
/usr/local/bin/sendEmail -f $FRUSER -t ${DBAEMAIL} -bcc $BCCUSER -s $SMTP -u "$IP arclog not reply" -o message-file=arc_not_reply.log -xu "$FRUSER" -xp "$USERPWD"
exit
else
echo `date +'%F %T'`" All the archive log have replyed" >arc_replyok.txt
/usr/local/bin/sendEmail -f $FRUSER -t ${DBAEMAIL} -bcc $BCCUSER -s $SMTP -u "$IP arc_replyok" -o message-file=arc_replyok.txt -xu "$FRUSER" -xp "$USERPWD"
fi
exit
并且,/usr/local/bin/sendEmail是一個(gè)命令,希望執(zhí)行成功需要先安裝sendEmail
安裝步驟如下:
sendEmail下載地址:http://caspian.dotconf.net/menu/Software/SendEmail/
# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz //下載1.56版本
# tar -xzvf sendEmail-v1.56.tar.gz //解壓后就可以使用了
# mv sendEmail /usr/local/bin/
以上是“SHELL腳本如何檢查Oracle DG備庫(kù)是否已經(jīng)應(yīng)用歸檔”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。