#!/bin/ksh export SID=$1 export DG_SID=$2 export NUMBER_OF_ARCHIVELOGS_THRESHOLD=$3 [ "$SID" = "" ] && { print "SID is a required parameter"; print $USAGE; exit 1; } [ "$DG_SID" = "" ] && { print "DG_SID is a required parameter"; print $USAGE; exit 1; } [ "$NUMBER_OF_ARCHIVELOGS_THRESHOLD" = "" ] && { print "NUMBER_OF_ARCHIVELOGS_THRESHOLD is a required parameter"; print $USAGE; exit 1; } FN=`echo $0 | sed s/\.*[/]//` # ------------------------------------------------------------------------------------------ # INITIAL SETUP # ------------------------------------------------------------------------------------------ export ORACLE_BASE=`grep -i ^oracle: /etc/passwd | cut -d: -f6` . $ORACLE_BASE/general/sh/functions.ksh set_basics; # ---------------------- # CONFIGURATION SECTION # ---------------------- # Ksh version issue # So enter it again here #----------------------------------------------- export FILENAME=$(basename $0 |awk -F"." {'print $1'}) export CONFIG_FILE="${SH}"/"${FILENAME}".conf export CONTROL_FILE="${SH}"/"${FILENAME}".ctl set_oratab; source_config_file; #--------------------------------------------------------------------- # Setup the Oracle Environment and pass the ORACLE_SID #--------------------------------------------------------------------- [ -d /var/opt/oracle/bin ] && export BINDIR=/var/opt/oracle/bin || export BINDIR=$HOME/general/sh/bin . $BINDIR/oracle_setup.ksh `$BINDIR/getsid.ksh` function show_debug_parameters { echo "Max Number of Alerts: $MAX_NUMBER_ALERTS" echo "Counter: $COUNTER" print "Primary: $MAX_SEQ and DG: $MAX_DG_SEQ" } export LOGFILE=/tmp/dg_archive_log_comparison.${SID}.alert [ -f "$LOGFILE" ] && rm $LOGFILE export PRIMARY_ARCHIVELOG=/tmp/dg_archive_log_p.log export DG_ARCHIVELOG=/tmp/dg_archive_log_dg.log export MERGED_ARCHIVELOG=/tmp/dg_archive_log_merged.log function dg_archive_log_monitor { print " set head off pages 0 feed off ver off lines 2000 trims on select 'thread'||thread#, rtrim(ltrim(max(sequence#))) from v\$log_history group by thread# order by 1; " |sqlplus -s rodba/$(cat $SH/.rodba.pw)@${SID} > $PRIMARY_ARCHIVELOG THREADS_P=$(wc -l $PRIMARY_ARCHIVELOG |awk {'print $1'}) print "Primary Threads: $THREADS_P" p=0 while [ $p -lt ${THREADS_P} ] do (( p=p+1 )) print "p: $p" [ $p -eq 1 ] && export PT1=$(cat $PRIMARY_ARCHIVELOG |grep -i thread1 |awk {'print $2'}) [ $p -eq 2 ] && export PT2=$(cat $PRIMARY_ARCHIVELOG |grep -i thread2 |awk {'print $2'}) [ $p -eq 3 ] && export PT3=$(cat $PRIMARY_ARCHIVELOG |grep -i thread3 |awk {'print $2'}) done print $PT1 $PT2 $PT3 print " set head off pages 0 feed off ver off lines 2000 trims on select 'thread'||thread#, rtrim(ltrim(max(sequence#))) from v\$archived_log where applied <> 'NO' group by thread# order by 1; " |sqlplus -s sys/$(cat $SH/.sys.${DG_SID}.pw)@${DG_SID} as sysdba > $DG_ARCHIVELOG THREADS_DG=$(wc -l $DG_ARCHIVELOG |awk {'print $1'}) dg=0 while [ $dg -lt ${THREADS_P} ] do (( dg=dg+1 )) print "dg: $dg" [ $dg -eq 1 ] && export DGT1=$(cat $DG_ARCHIVELOG |grep -i thread1 |awk {'print $2'}) [ $dg -eq 2 ] && export DGT2=$(cat $DG_ARCHIVELOG |grep -i thread2 |awk {'print $2'}) [ $dg -eq 3 ] && export DGT3=$(cat $DG_ARCHIVELOG |grep -i thread3 |awk {'print $2'}) done print $DGT1 $DGT2 $DGT3 cat $PRIMARY_ARCHIVELOG $DG_ARCHIVELOG |sort > $MERGED_ARCHIVELOG #cat $MERGED_ARCHIVELOG (( T1_DIFF = $PT1 - $DGT1 )) (( T2_DIFF = $PT2 - $DGT2 )) #(( DELTA_SEQ = $MAX_SEQ - $MAX_DG_SEQ )) #export DIFF_SEQ=$DELTA_SEQ #if [ $MAX_SEQ -ne $MAX_DG_SEQ ]; then if [[ $T1_DIFF -gt $NUMBER_OF_ARCHIVELOGS_THRESHOLD || $T2_DIFF -gt $NUMBER_OF_ARCHIVELOGS_THRESHOLD ]]; then #print "Primary: $MAX_SEQ and DG: $MAX_DG_SEQ Archive Logs are not in sync" >$LOGFILE print "Primary $SID and Data Guard $DG_SID ArchiveLogs are not in sync \n" >$LOGFILE print "There is a gap in Archive Log Sequence of: $T1_DIFF for Thread#1 and $T2_DIFF for Thread#2" >>$LOGFILE cat $MERGED_ARCHIVELOG >> $LOGFILE (( EMAIL_COUNTER = ${COUNTER} + 1 )) # Set ALERT_COUNTER to be used by alert_notification.ksh export ALERT_COUNTER=$EMAIL_COUNTER $SH/alert_notification.ksh $FN `hostname` $SID "$DG_SID" "Primary: $MAX_SEQ and DG: $MAX_DG_SEQ Archive Logs are not in sync" $LOGFILE # Increment the counter by one and append it to the LOGFILE filename (( COUNTER = ${COUNTER} + 1 )) echo $COUNTER mv ${LOGFILE} ${LOGFILE}.${COUNTER} fi #fi } #+++++++++++++++++++++++++++++++++++++++++++++++++++++ # MAIN LOGIC #+++++++++++++++++++++++++++++++++++++++++++++++++++++ #-------------------------------------------- # Count the number of log files ($LOGFILE) # in the /tmp directory #-------------------------------------------- if [ -f ${LOGFILE}.* ]; then export COUNTER=$(ls ${LOGFILE}.* |wc -l) else COUNTER=0 fi # -- Check for DG password file [ ! -f $SH/.sys.$DG_SID.pw ] && { print "DG_SID: $DG_SID password file not found!"; exit 1; } if [ "${COUNTER}" -ge "$MAX_NUMBER_ALERTS" ]; then echo "EXCEEDED Max number of Alerts: $MAX_NUMBER_ALERTS" else dg_archive_log_monitor; show_debug_parameters; fi