Shell Script to Automatically Start Oracle GoldenGate Process and Notification

Here is a shell script that can monitor your Oracle GoldenGate processes and start them if they are abended. It will make two attempts and if the process still abends, send notification to interested parties.

If you want to disable monitoring of GoldenGate processes, place an empty file called gg_monitoring_stop in the directory where you place this Shell Script.

#!/bin/bash

# Stop monitoring if empty file "gg_monitoring_stop" is
# present in current directory
if [[ -f ./gg_monitoring_stop ]]; then
  exit
fi

# Group distribution
MAIL_LIST=toall@company.com

MAIL_SUB="OGG Status"

ABEND_FND=/tmp/ogg_abend.found
TMP_CACHE=/tmp/ogg_cache
DASHES='-----------------------------------------------------'
START_FAILED_MSG="Could not start some of Oracle GoldenGate processes. Please start manually"

# Setting ORACLE_HOME
ORAENV_ASK=NO
export ORAENV_ASK
ORACLE_SID=voice
export ORACLE_SID
. oraenv > /dev/null
ORACLE_SID=
export ORACLE_SID

OGG_HOME=/opt/oracle/product/11.2.0/ogg_1
OGG_HOME=/u01/ogg1

SLEEP_TIME_SEC=10

cd ${OGG_HOME}

function initialize
{
   echo > ${ABEND_FND}
   echo > ${TMP_CACHE}
   echo ${DASHES} >> $ABEND_FND
   echo "Host    : `hostname`" >> ${ABEND_FND}
   echo "Date    : `date`" >> ${ABEND_FND}
   echo "GG Home : ${OGG_HOME}" >> ${ABEND_FND}
   echo ${DASHES} >> ${ABEND_FND}
}
function ulns
{
   perl -e 'print "-"x42; print "\n"' >> $ABEND_FND
}
function send_email
{
  uuencode ${ABEND_FND} ${ABEND_FND} | mailx -s ${MAIL_SUB} ${MAIL_LIST}
}

function prnt_proc_stats
{
   echo "info all" | ggsci >> $TMP_CACHE
   echo >> $ABEND_FND

   print "Process       Name          Status" >> $ABEND_FND
   ulns
   while read c
   do
      pros=`echo $c | awk '{print $1}'`
      stat=`echo $c | awk '{print $2}'`
      oggnme=`echo $c | awk '{print $3}'`
         if [[ `echo $c | egrep '(JAGENT|EXTRACT|REPLICAT)'` ]]; then
            printf "%-13s %-13s %-13s\n" $pros $oggnme $stat >> $ABEND_FND
         fi
   done < $TMP_CACHE
   ulns
   echo >> $ABEND_FND
   rm -f $TMP_CACHE
}

function mgr_status
{
   # Check if MANAGER is RUNNING. If not, send alert, exit
   mgr_stts=`echo "info all" | ggsci | grep MANAGER | awk '{print $2}'`
   if [[ $mgr_stts != 'RUNNING' ]];then
      echo >> $ABEND_FND
      echo "MANAGER Status : ${mgr_stts}" >> $ABEND_FND
      echo >> $ABEND_FND
      echo "  Please start MANAGER and remaining processes." >> $ABEND_FND
      prnt_proc_stats
      exit
   fi
}

function check_start
{
   mgr_status

   echo "info all" | ggsci | while read lne
   do
     if [[ `echo $lne | egrep '(MANAGER|JAGENT|EXTRACT|REPLICAT)'` ]]; then

        ptype=`echo $lne | awk '{print $1}'`
        pstatus=`echo $lne | awk '{print $2}'`
        pname=`echo $lne | awk '{print $3}'`

        # Start EXTRACT, REPLICAT processes
        if [[ ! `echo $lne | egrep '(MANAGER|JAGENT)'` ]]; then
           if [[ $pstatus = 'ABENDED' ]]; then
              echo "$ptype $pname $pstatus" >> $ABEND_FND
              echo "start ${ptype} ${pname}" | ggsci > /dev/null
           fi
        fi
     fi
   done
}

initialize
check_start

if [[ -f ${ABEND_FND} ]]; then
    send_email
#    rm -f ${ABEND_FND}
    sleep ${SLEEP_TIME_SEC}
    check_start
    if [[ -f ${ABEND_FND} ]]; then
       echo ${START_FAILED_MSG} >> ${ABEND_FND}
       send_email
#       rm -f ${ABEND_FND}
    fi
fi
Comments