Views

Thursday, September 14, 2017

ASM, Database, Listener, Goldengate Start/Stop Automation Script

ASM, database, listener, goldengate start/stop automation script.

This shell script will start/stop ASM instance, oracle database, listener and goldengate.
We can also check the current status of above.
This is a menu driven program to perform following operations.

1. Stop Database
2. Stop ASM + DB
3. Stop Listener
4. Stop Goldengate
5. Start Database
6. Start ASM + DB
7. Start Listener
8. Start Goldengate
9. Check Database and ASM Status
10. Check Listener Status
11. Check Goldengate Status

This script start/stop database named oraprod and listener with specific names, but it can be customized to stop any database and listner.

Below is the script used.
After the script we can find the sample execution of script.
Please let me know if the script helped you.

#!/bin/bash
## -----------------------------------------------------------------------------------
## File Name    : /home/oracle/scripts/asm_start_stop.sh
## Description  : Script to start / stop ASM, oraprod database and listener on server
## Call Syntax  : sh /home/oracle/scripts/asm_start_stop.sh
## Last Modified: 9/14/2017
## -----------------------------------------------------------------------------------
## Revision history:

## -----------------------------------------------------------------------------------
PATH=$PATH:/usr/local/bin
export PATH
export ORACLE_HOME=`cat /etc/oratab|grep oraprod |grep -v "^#"|cut -d: -f2 -s`
export GRID_HOME=`cat /etc/oratab|grep '+ASM' |grep -v "^#"|cut -d: -f2 -s`
export PATH=${PATH}:${ORACLE_HOME}/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GG_HOME
export SCRIPT_HOME=/home/oracle/scripts
log_dir=$SCRIPT_HOME/logs
LOG_FILE=$log_dir/stop_start.txt


##############################################################################
# function to log messages
# Along with messages displayed on console, all logs will be recorded in
# a log file created under log directory
# This file is always appended to retain previous execution log
# log will contain the username who has executed and
# date and time when it was executed
##############################################################################

logit()
{
   if [ ! -d "$log_dir" ]; then
     if [ ! -f "$LOG_FILE" ]; then
       echo "Log directory $log_dir or Log file $LOG_FILE does not exist. Please create and re-execute."
       exit ;
     fi
   fi
   echo "[${USER}][`date`] - ${*}" >> ${LOG_FILE}
}

##############################################################################
# check if log directory exist
# if log directory does not exist, exit the code with message
# displayed on console
##############################################################################

logit "Checking log directory"
if [ ! -d "$log_dir" ]; then
logit "Log directory $log_dir does not exist. Please create and re-execute"
echo "Log directory $log_dir does not exist. Please create and re-execute"
exit ;
fi

##############################################################################
# Script usage check
# check if script has been executed with proper parameters
# If not, exit the code
##############################################################################
if [ "$#" -ne 0 ]; then
  echo "Usage: sh asm_start_stop.sh"
  exit 1
fi

##############################################################################
# check if logged on with oracle user
# If not, exit the code
##############################################################################

if [ `whoami` != "oracle" ]; then
  echo "Must be logged on as oracle to run this script."
  exit 1
fi

##############################################################################
# check if ORATAB exist
# If not, exit the code
##############################################################################

logit "Checking ORATAB"
ORATAB=/etc/oratab
if [ ! $ORATAB ] ; then
  echo "$ORATAB not found"
  exit ;
fi

asm=`ps -ef | grep pmon_+ASM | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`

##############################################################################
# Create start.sh, stop.sh, asmstart.sh and asmstop.sh
#
##############################################################################

if [ -f "$SCRIPT_HOME/dbstart.sh" ]; then
  rm $SCRIPT_HOME/dbstart.sh
fi
if [ -f "$SCRIPT_HOME/dbstop.sh" ]; then
  rm $SCRIPT_HOME/dbstop.sh
fi
if [ -f "$SCRIPT_HOME/asmstop.sh" ]; then
  rm $SCRIPT_HOME/asmstop.sh
fi
if [ -f "$SCRIPT_HOME/asmstart.sh" ]; then
  rm $SCRIPT_HOME/asmstart.sh
fi

if [ ! -f "$SCRIPT_HOME/dbstart.sh" ]; then
logit "Creating dbstart.sh"
cat > $SCRIPT_HOME/dbstart.sh << EOF1
sqlplus '/as sysdba'<<!
startup
show parameter db_name
select open_mode from v\$database ;
exit
!
EOF1
chmod 755 $SCRIPT_HOME/dbstart.sh
fi


if [ ! -f "$SCRIPT_HOME/dbstop.sh" ]; then
logit "Creating dbstop.sh"
cat > $SCRIPT_HOME/dbstop.sh << EOF2
sqlplus '/as sysdba'<<!
select name, open_mode from v\$database ;
show parameter db_name
shut immediate
exit
!
EOF2
chmod 755 $SCRIPT_HOME/dbstop.sh
fi

if [ ! -f "$SCRIPT_HOME/asmstop.sh" ]; then
logit "Creating asmstop.sh"
cat > $SCRIPT_HOME/asmstop.sh << EOF3
\$ORACLE_HOME/bin/crsctl status res -t
\$ORACLE_HOME/bin/crsctl stop has
exit
!
EOF3
chmod 755 $SCRIPT_HOME/asmstop.sh
fi

if [ ! -f "$SCRIPT_HOME/asmstart.sh" ]; then
logit "Creating asmstart.sh"
cat > $SCRIPT_HOME/asmstart.sh << EOF4
\$ORACLE_HOME/bin/crsctl start has
\$ORACLE_HOME/bin/crsctl status res -t
exit
!
EOF4
chmod 755 $SCRIPT_HOME/asmstart.sh
fi


##############################################################################
# Shutdown Goldengate
# Function to stop goldengate (extract or replicat)
##############################################################################

stopgg() {
logit "Entering: Stop Goldengate"
str=`ps -ef |grep mgr.prm |grep -v grep | awk '{print $10}'`
if [ str = "" ]; then
  echo "Goldengate does not exist or MGR not started"
  exit ;
else
  ind=(`echo $str | grep -b -o dirprm | cut -d':' -f 1`)
  ind=$(($ind-1))
  export GG_HOME=`echo $str | cut -c 1-$ind`
fi
cd $GG_HOME
./ggsci << EOF > $log_dir/gginfo.txt
info all
EOF
log_file=$log_dir/gginfo.txt

ext_name=`cat $log_dir/gginfo.txt |grep EXTRACT | awk '{print $3}'`
rep_name=`cat $log_dir/gginfo.txt |grep REPLICAT | awk '{print $3}'`
counte=(`echo $ext_name | wc -w`)
countr=(`echo $rep_name | wc -w`)

# check if EXTRACT process is there
if [[ $counte > 0 ]]; then
PROCESS="EXTRACT"
./ggsci << EOF > $log_dir/gginfo.txt
stop E*
EOF
fi

# check if REPLICAT process is there
if [[ $countr > 0 ]]; then
PROCESS="REPLICAT"
./ggsci << EOF > $log_dir/gginfo.txt
stop R*
EOF
fi
logit "Goldengate Stopped. Please check detail status using Menu option: \"Check Goldengate Status\""
echo "Goldengate Stopped. Please check detail status using Menu option: \"Check Goldengate Status\""

}

##############################################################################
# Start Goldengate
# Function to Start goldengate (extract or replicat)
##############################################################################

startgg() {
  logit "Entering: Start Goldengate"
str=`ps -ef |grep mgr.prm |grep -v grep | awk '{print $10}'`
if [ str = "" ]; then
  echo "Goldengate does not exist or MGR not started"
  exit ;
else
  ind=(`echo $str | grep -b -o dirprm | cut -d':' -f 1`)
  ind=$(($ind-1))
  export GG_HOME=`echo $str | cut -c 1-$ind`
fi
cd $GG_HOME
./ggsci << EOF > $log_dir/gginfo.txt
info all
EOF
log_file=$log_dir/gginfo.txt

ext_name=`cat $log_dir/gginfo.txt |grep EXTRACT | awk '{print $3}'`
rep_name=`cat $log_dir/gginfo.txt |grep REPLICAT | awk '{print $3}'`
counte=(`echo $ext_name | wc -w`)
countr=(`echo $rep_name | wc -w`)

# start mgr
./ggsci << EOF > $log_dir/gginfo.txt
start mgr
EOF

# check if EXTRACT process is there
if [[ $counte > 0 ]]; then
PROCESS="EXTRACT"
./ggsci << EOF > $log_dir/gginfo.txt
start E*
EOF
fi

# check if REPLICAT process is there
if [[ $countr > 0 ]]; then
PROCESS="REPLICAT"
./ggsci << EOF > $log_dir/gginfo.txt
start R*
EOF
fi
logit "Goldengate Started. Please check detail status using Menu option: \"Check Goldengate Status\""
echo "Goldengate Started. Please check detail status using Menu option: \"Check Goldengate Status\""
}

##############################################################################
# Check goldengate status
# Function to check status of goldengate (extract or replicat)
##############################################################################


ggstatus() {
str=`ps -ef |grep mgr.prm |grep -v grep | awk '{print $10}'`
if [ $str = "" ]; then
  echo "Goldengate does not exist or MGR not started"
  exit ;
else
  ind=(`echo $str | grep -b -o dirprm | cut -d':' -f 1`)
  ind=$(($ind-1))
  export GG_HOME=`echo $str | cut -c 1-$ind`
fi
cd $GG_HOME
./ggsci << EOF > $SCRIPT_HOME/infostatus.txt
info all
exit
EOF

cat $SCRIPT_HOME/infostatus.txt
echo $'\n'


}

##############################################################################
# Start asm instance
# This will start asm instance +ASM
##############################################################################

startasm() {
   logit "Entering: Start ASM"
   export ORACLE_SID=+ASM
   export ORACLE_HOME=$GRID_HOME
   export PATH=${PATH}:${ORACLE_HOME}/bin
   export LD_LIBRARY_PATH=$ORACLE_HOME/lib:
   if [ ! -x $GRID_HOME/bin/crsctl ]; then
     logit "$ORACLE_HOME/bin/crsctl not found when attempting to start"
     logit "  ASM instance $GRID_SID."
     exit
   fi
   RCcss=`$GRID_HOME/bin/crsctl check css`
   RCcssv=$?
   if [ "$RCcssv" = 0 ] ; then
     STATUS="-1"
     logit "Warning: \"${ORACLE_SID}\" already started."
     echo "Warning: \"${ORACLE_SID}\" already started."
     exit
   fi
   if [ "$RCcssv" = 1 ] ; then
     echo "Starting up \"$ORACLE_SID\""
     logit "Starting up \"$ORACLE_SID\""
     nohup sh $SCRIPT_HOME/asmstart.sh &
     COUNT=0

     while [ "$RCcssv" = 1 ]; do
       COUNT=`expr $COUNT + 1`
       if [ $COUNT = 15 ] ; then
         # 15 tries with 20 sec interval => 5 minutes timeout
         logit "Timed out waiting to start ASM instance $ORACLE_SID"
         logit "  CSS service is NOT available."
         exit $COUNT
       fi
      logit "Waiting for Oracle CSS service to be available before starting "
      logit " ASM instance $GRID_SID. Wait $COUNT."
      echo "ASM instance $ORACLE_SID starting. Please wait...."
      sleep 20
      RCcss=`$GRID_HOME/bin/crsctl check css`
      RCcssv=$?
    done
    if [ "$RCcssv" = 1 ] ; then
      logit "\"${ORACLE_SID}\" instance successfully started."
      echo "\"${ORACLE_SID}\" instance successfully started."
    fi
  fi
}

##############################################################################
# Shutdown ASM instance
# This will stop asm instance +ASM
##############################################################################


stopasm() {
   logit "Entering: Stop ASM"
   export ORACLE_SID=+ASM
   export ORACLE_HOME=$GRID_HOME
   export PATH=${PATH}:${ORACLE_HOME}/bin
   export LD_LIBRARY_PATH=$ORACLE_HOME/lib:
   if [ ! -x $GRID_HOME/bin/crsctl ]; then
     logit "$ORACLE_HOME/bin/crsctl not found when attempting to stop"
     logit "  ASM instance $GRID_SID."
     exit
   fi
   RCcss=`$GRID_HOME/bin/crsctl check css`
   RCcssv=$?
   if [ "$RCcssv" = 1 ] ; then
     STATUS="-1"
     logit "Warning: \"${ORACLE_SID}\" already down."
     echo "Warning: \"${ORACLE_SID}\" already down."
   fi
   if [ "$RCcssv" = 0 ] ; then
     echo "Shutting down  \"$ORACLE_SID\""
     logit "Shutting down  \"$ORACLE_SID\""
     nohup sh $SCRIPT_HOME/asmstop.sh &
     COUNT=0

     while [ "$RCcssv" = 0 ]; do
       COUNT=`expr $COUNT + 1`
       if [ $COUNT = 15 ] ; then
         # 15 tries with 20 sec interval => 5 minutes timeout
         logit "Timed out waiting to stop ASM instance $ORACLE_SID"
         logit "  CSS service is NOT available."
         exit $COUNT
       fi
      logit "Waiting for Oracle CSS service to be down before stopping "
      logit " ASM instance $GRID_SID. Wait $COUNT."
      echo "ASM instance $ORACLE_SID stopping. Please wait...."
      sleep 20
      RCcss=`$GRID_HOME/bin/crsctl check css`
      RCcssv=$?
    done
    if [ "$RCcssv" = 1 ] ; then
      logit "\"${ORACLE_SID}\" instance successfully stopped."
      echo "\"${ORACLE_SID}\" instance successfully stopped."
    fi
  fi
}

##############################################################################
# Shutdown database
# Function stops only oraprod database, but it can be customized to stop
# any or all oracle databases
##############################################################################


stopdb() {
  logit "Entering: Stop oraprod Database"
  export ORACLE_SID=oraprod
  db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
  if [ "$db" = 0 ] ; then
    STATUS="-1"
    logit "Warning: \"${ORACLE_SID}\" already down."
    echo "Warning: \"${ORACLE_SID}\" already down."
  fi
  if [ "$db" != 0 ] ; then
    echo "Shutting down database \"$ORACLE_SID\""
    logit "Shutting down database \"$ORACLE_SID\""
    nohup sh $SCRIPT_HOME/dbstop.sh &
    COUNT=0
    while [ "$db" != 0 ];
    do
      COUNT=`expr $COUNT + 1`
      if [ $COUNT = 15 ] ; then
        # 15 tries with 20 sec interval => 5 minutes timeout
        logit "Timed out waiting to stop db instance $ORACLE_SID"
        logit "  DB not able to stop."
        exit $COUNT
      fi
      logit "Waiting for Oracle database to be stopped"
      logit " DB instance $ORACLE_SID. Wait $COUNT."
      echo "Oracle database $ORACLE_SID stopping. Please wait...."
      sleep 20
      db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
    done
    db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
    if [ "$db" = 0 ] ; then
      logit "\"${ORACLE_SID}\" database successfully stopped."
      echo "\"${ORACLE_SID}\" database successfully stopped."
    fi
  fi
}

##############################################################################
# Startup database
# Function starts only oraprod database, but it can be customized to start
# any or all oracle databases
##############################################################################

startdb() {
  logit "Entering: Start oraprod Database"
  export ORACLE_SID=oraprod
  db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
  if [ "$db" != 0 ] ; then
    STATUS="-1"
    logit "Warning: \"${ORACLE_SID}\" already started."
    echo "Warning: \"${ORACLE_SID}\" already started."
  fi
  if [ "$db" = 0 ] ; then
    echo "Starting up database \"$ORACLE_SID\""
    logit "Starting up database \"$ORACLE_SID\""
    nohup sh $SCRIPT_HOME/dbstart.sh &
    COUNT=0
    while [ "$db" = "0" ];
      do
     COUNT=`expr $COUNT + 1`
      if [ $COUNT = 15 ] ; then
        # 15 tries with 20 sec interval => 5 minutes timeout
        logit "Timed out waiting to start db instance $ORACLE_SID"
        logit "  DB not able to start."
        exit $COUNT
      fi
      logit "Waiting for Oracle database to be started"
      logit " DB instance $ORACLE_SID. Wait $COUNT."
      echo "Oracle database $ORACLE_SID starting. Please wait...."
      sleep 20
      db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
    done
    db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
    if [ "$db" != 0 ] ; then
      logit "\"${ORACLE_SID}\" database successfully started."
      echo "\"${ORACLE_SID}\" database successfully started."
    fi
  fi
}

##############################################################################
# Check status of ASM and Database
# This function will check status of +ASM instance and oraprod database
##############################################################################


checkasmdb() {
  logit "Entering: Checking ASM and Database status"
  if [ ! -x $GRID_HOME/bin/crsctl ]; then
    logit "$ORACLE_HOME/bin/crsctl not found when attempting to stop"
    logit "ASM instance $GRID_SID."
  else
    status=0
    RChas=`$GRID_HOME/bin/crsctl check has`
    RChasv=$?
    if [ "$RChas" = "CRS-4639: Could not contact Oracle High Availability Services" ] ; then
      status=-1
      logit "$RChas"
    fi
   
    if [ $status != -1 ]&&[ "$RChasv" = 0 ] ; then
      logit "$RChas"
      #echo "CRS-4638: Oracle High Availability Services is online"
    fi
   
    RCcss=`$GRID_HOME/bin/crsctl check css`
    RCcssv=$?
    if [ $status != -1 ]&&[ "$RCcssv" = 0 ] ; then
      logit "$RCcss"
      #echo "CRS-4529: Cluster Synchronization Services is online"
    fi
   
    RCcssd=`$GRID_HOME/bin/crsctl check cssd`
    RCcssdv=$?
    if [ $status = 0 ]&&[ "$RCcssdv" = 0 ] ; then
      logit "$RCcssd"
      #echo "CRS-272: Cluster Synchronization Services is online"
    fi
  fi
  if [ $status != -1 ]&&[ "$RChasv" = 0 ]&&[ "$RCcssv" = 0 ]&&[ "$RCcssdv" = 0 ] ; then
    logit "ASM is up and running"
    echo "ASM is up and running"
  else
    logit "ASM instance is down"
    echo "ASM instance is down"
  fi
  db=`ps -ef | grep pmon_oraprod | grep -v grep | awk -F_ '{ print $3 }'|wc -l`
  if [ "$db" = 1 ] ; then
    logit "oraprod database up and running"
    echo "oraprod database up and running"
  else
    logit "oraprod database not started"
    echo  "oraprod database not started"
  fi
}

##############################################################################
# Stop Listener
# Function to stop customized listener
# can be customized for other listner names
##############################################################################


stoplsnr() {
   export ORACLE_SID=+ASM
   export ORACLE_HOME=$GRID_HOME
   export PATH=${PATH}:${ORACLE_HOME}/bin
   export LD_LIBRARY_PATH=$ORACLE_HOME/lib:

  if [ ! -x ${ORACLE_HOME}/bin/lsnrctl ]
  then
    echo
    logit "\t\"ORACLE_HOME/bin/lsnrctl\" not found; aborting..."
    echo "\t\"ORACLE_HOME/bin/lsnrctl\" not found; aborting..."
    echo
    exit 1
  fi

  if [ "$HOSTNAME" = 'racnode7-old.localdomain' ]||[ "$HOSTNAME" = 'racnode7.localdomain' ]||[ "$HOSTNAME" = 'racnode7' ] ;
  then lsnname=LISTENER_AC7;
  fi
  if [ "$HOSTNAME" = 'racnode8-old.localdomain' ]||[ "$HOSTNAME" = 'racnode8.localdomain' ];
  then lsnname=LISTENER_AC8;
  fi
  if [ "$HOSTNAME" = 'racnode9-old.localdomain' ]||[ "$HOSTNAME" = 'racnode9.localdomain' ];
  then lsnname=LISTENER_AC9;
  fi
  if [ "$HOSTNAME" = 'racnode10-old.localdomain' ]||[ "$HOSTNAME" = 'racnode10.localdomain' ];
  then lsnname=LISTENER_AC10;
  fi
  if [ "$HOSTNAME" = 'racnode11-old.localdomain' ]||[ "$HOSTNAME" = 'racnode11.localdomain' ];
  then lsnname=LISTENER_AC11;
  fi
 
  logit "Entering: Stopping Listener $lsnname"
  c=`ps -ef | grep -v grep | grep $lsnname | wc -l`

  if test $c -eq 0
  then
    echo "Warning: no listener running"
    logit "Warning: no listener running"
  else
    echo "Stopping listener $lsnname "
    logit "Stopping listener $lsnname "
    s=`lsnrctl stop $lsnname`
    sleep 15
    c=`ps -ef | grep -v grep | grep $lsnname | wc -l`
    if [ $c = 0 ] ; then
      logit "Listener $lsnname successfully stopped"
      echo "Listener $lsnname successfully stopped"
    else
      logit "Listener $lsnname failed to stop"
      echo "Listener $lsnname failed to stop"
    fi
  fi
}

##############################################################################
# Start Listener
# Function to Start customized listener
# can be customized for other listner names
##############################################################################

startlsnr() {
   export ORACLE_SID=+ASM
   export ORACLE_HOME=$GRID_HOME
   export PATH=${PATH}:${ORACLE_HOME}/bin
   export LD_LIBRARY_PATH=$ORACLE_HOME/lib:

  if [ ! -x ${ORACLE_HOME}/bin/lsnrctl ]
  then
    echo
    logit "\t\"ORACLE_HOME/bin/lsnrctl\" not found; aborting..."
    echo "\t\"ORACLE_HOME/bin/lsnrctl\" not found; aborting..."
    echo
    exit 1
  fi

  if [ "$HOSTNAME" = 'racnode7-old.localdomain' ]||[ "$HOSTNAME" = 'racnode7.localdomain' ]||[ "$HOSTNAME" = 'racnode7' ] ;
  then lsnname=LISTENER_AC7;
  fi
  if [ "$HOSTNAME" = 'racnode8-old.localdomain' ]||[ "$HOSTNAME" = 'racnode8.localdomain' ];
  then lsnname=LISTENER_AC8;
  fi
  if [ "$HOSTNAME" = 'racnode9-old.localdomain' ]||[ "$HOSTNAME" = 'racnode9.localdomain' ];
  then lsnname=LISTENER_AC9;
  fi
  if [ "$HOSTNAME" = 'racnode10-old.localdomain' ]||[ "$HOSTNAME" = 'racnode10.localdomain' ];
  then lsnname=LISTENER_AC10;
  fi
  if [ "$HOSTNAME" = 'racnode11-old.localdomain' ]||[ "$HOSTNAME" = 'racnode11.localdomain' ];
  then lsnname=LISTENER_AC11;
  fi
  logit "Entering: Starting Listener $lsnname"
  c=`ps -ef | grep -v grep | grep $lsnname | wc -l`

  if test $c -eq 0
  then
    echo "Starting listener $lsnname "
    logit "Starting listener $lsnname "
    s=`lsnrctl start $lsnname`
    sleep 15
    c=`ps -ef | grep -v grep | grep $lsnname | wc -l`
    if test $c -eq 0
    then
      logit "Listener $lsnname failed to start"
      echo "Listener $lsnname failed to start"
    else
      logit "Listener $lsnname successfully started"
      echo "Listener $lsnname successfully started"
    fi
  else
    echo "Warning: Listener already running"
    logit "Warning: Listener already running"

  fi
}

##############################################################################
# Check status of Listener
#
##############################################################################

chklsnr() {
  logit "Entering: Checking Listener status"
  if [ ! -x ${ORACLE_HOME}/bin/tnsping ]
  then
    echo
    logit "\t\"ORACLE_HOME/bin/tnsping\" not found; aborting..."
    echo "\t\"ORACLE_HOME/bin/tnsping\" not found; aborting..."
    echo
    exit 1
  fi

  if [ ! -x ${ORACLE_HOME}/bin/lsnrctl ]
  then
    echo
    logit "\t\"ORACLE_HOME/bin/lsnrctl\" not found; aborting..."
    echo "\t\"ORACLE_HOME/bin/lsnrctl\" not found; aborting..."
    echo
    exit 1
  fi
  if [ "$HOSTNAME" = 'racnode7-old.localdomain' ]||[ "$HOSTNAME" = 'racnode7.localdomain' ]||[ "$HOSTNAME" = 'racnode7' ] ;
  then lsnname=LISTENER_AC7;
  fi
  if [ "$HOSTNAME" = 'racnode8-old.localdomain' ]||[ "$HOSTNAME" = 'racnode8.localdomain' ];
  then lsnname=LISTENER_AC8;
  fi
  if [ "$HOSTNAME" = 'racnode9-old.localdomain' ]||[ "$HOSTNAME" = 'racnode9.localdomain' ];
  then lsnname=LISTENER_AC9;
  fi
  if [ "$HOSTNAME" = 'racnode10-old.localdomain' ]||[ "$HOSTNAME" = 'racnode10.localdomain' ];
  then lsnname=LISTENER_AC10;
  fi
  if [ "$HOSTNAME" = 'racnode11-old.localdomain' ]||[ "$HOSTNAME" = 'racnode11.localdomain' ];
  then lsnname=LISTENER_AC11;
  fi
  logit "Checking for Listener $lsnname"
  c=`ps -ef | grep -v grep | grep $lsnname | wc -l`

  if test $c -eq 0
  then
    logit "no listener running"
    echo "no listener running"
  else
    logit "listener $lsnname is up and running"
    echo "listener $lsnname is up and running"
  fi
}


##############################################################################
# Drawing menu function
# This function will draw memu on console to select option either
# to start/stop SAP instance
##############################################################################

draw_menu(){
    NORMAL=`echo "\033[m"`
    MENU=`echo "\033[36m"` #Blue
    NUMBER=`echo "\033[33m"` #yellow
    FGRED=`echo "\033[41m"`
    RED_TEXT=`echo "\033[31m"`
    ENTER_LINE=`echo "\033[33m"`
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${MENU}     Database Resources Start / Stop ${NORMAL}"
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${MENU}**${NUMBER} 1)${MENU} Stop Database ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 2)${MENU} Stop ASM + DB ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 3)${MENU} Stop Listener ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 4)${MENU} Stop Goldengate ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 5)${MENU} Start Database ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 6)${MENU} Start ASM + DB ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 7)${MENU} Start Listener ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 8)${MENU} Start Goldengate ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 9)${MENU} Check Database and ASM Status ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 10)${MENU} Check Listener Status ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 11)${MENU} Check Goldengate Status ${NORMAL}"
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${ENTER_LINE}Please enter a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}"
    read Choice
}
function choice_select() {
    COLOR='\033[01;31m' # bold red
    RESET='\033[00;00m' # normal white
    MESSAGE=${@:-"${RESET}Error: No message passed"}
    echo -e "${COLOR}${MESSAGE}${RESET}"
}

##############################################################################
# Main function to execute the code to select the appropriate option
##############################################################################

clear
draw_menu
while [ Choice != '' ]
do
if [[ $Choice = "" ]]; then
        exit;
else
    case $Choice in
       1) choice_select "Stopping Database";
          stopdb;
          draw_menu;
         ;;
       2) choice_select "Stop ASM + DATABASE";
          stopasm;
          stopdb;
          draw_menu;
         ;;
       3) choice_select "Stopping Listener";
          stoplsnr;
          draw_menu;
         ;;
       4) choice_select "Stopping Goldengate";
          stopgg;
          draw_menu;
         ;;
       5) choice_select "Starting Database";
          startdb;
          draw_menu;
         ;;
       6) choice_select "Starting ASM + Database";
          startasm;
          startdb;
          draw_menu;
         ;;
       7) choice_select "Starting Listener";
          startlsnr;
          draw_menu;
         ;;
       8) choice_select "Start Goldengate";
          startgg;
          draw_menu;
         ;;
       9) choice_select "Check ASM + Database status";
          checkasmdb;
          draw_menu;
         ;;
       10) choice_select "Listener Status";
          chklsnr;
          draw_menu;
         ;;
       11) choice_select "Goldengate Status";
           ggstatus;
          draw_menu;
         ;;
        x)exit;
        ;;
        \n)exit;
        ;;
        *)clear;
        choice_select "Pick an option from the menu";
        draw_menu;
        ;;
    esac
fi
done

Sample Execution of shell script:-


 [oracle@testing~]$ cd scripts
[oracle@testing scripts]$ ls
asmstart.sh asm_start_stop.sh asmstop.sh dbstart.sh dbstatus.txt dbstop.sh
ggs_status_history.lst infostatus.txt logs
[oracle@testing scripts]$ sh asm_start_stop.sh

*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
9
Check ASM + Database status
ASM instance is down
oraprod database not started

*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
6
Starting ASM + Database
Starting up "+ASM"
nohup: appending output to `nohup.out'
ASM instance +ASM starting. Please wait....
Starting up database "oraprod"
nohup: appending output to `nohup.out'
Oracle database oraprod starting. Please wait....
Oracle database oraprod starting. Please wait....
Oracle database oraprod starting. Please wait....
Oracle database oraprod starting. Please wait....

Oracle database oraprod starting. Please wait....
"oraprod" database successfully started.

*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
9
Check ASM + Database status
ASM is up and running
oraprod database up and running
*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
10
Listener Status
listener LISTENER_AC8 is up and running
*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
11
Goldengate Status
Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.

GGSCI (testing.localdomain) 1>
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT ABENDED REP01 00:00:00 22:09:45
REPLICAT ABENDED REP02 00:00:00 22:09:51
REPLICAT ABENDED REP03 00:00:00 22:09:45
REPLICAT ABENDED REP04 00:00:00 22:09:45
REPLICAT ABENDED REP05 00:00:00 22:09:49
REPLICAT ABENDED REP06 00:00:00 22:09:51
REPLICAT ABENDED REP07 00:00:00 22:09:44
REPLICAT ABENDED REP08 00:00:00 22:09:49
REPLICAT ABENDED REP09 00:00:00 22:09:46
REPLICAT ABENDED REP10 00:00:00 22:09:42

GGSCI (testing.localdomain) 2>
*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
8
Start Goldengate
Goldengate Started. Please check detail status using Menu option: "Check Goldengate Status"

*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.
11
Goldengate Status
Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.

GGSCI (testing.localdomain) 1>
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REP01 00:00:00 00:00:03
REPLICAT RUNNING REP02 00:00:00 00:00:03
REPLICAT RUNNING REP03 00:00:00 00:00:03
REPLICAT RUNNING REP04 00:00:00 00:00:03
REPLICAT RUNNING REP05 00:00:00 00:00:03
REPLICAT RUNNING REP06 00:00:00 00:00:03
REPLICAT RUNNING REP07 00:00:00 00:00:03
REPLICAT RUNNING REP08 1342:56:45 00:00:03
REPLICAT RUNNING REP09 1342:56:46 00:00:03
REPLICAT RUNNING REP10 1342:56:40 00:00:03

GGSCI (testing.localdomain) 2>
*********************************************
Database Resources Start / Stop
*********************************************
** 1) Stop Database
** 2) Stop ASM + DB
** 3) Stop Listener
** 4) Stop Goldengate
** 5) Start Database
** 6) Start ASM + DB
** 7) Start Listener
** 8) Start Goldengate
** 9) Check Database and ASM Status
** 10) Check Listener Status
** 11) Check Goldengate Status
*********************************************
Please enter a menu option and enter or enter to exit.

1 comment:

  1. Hi, the script is fantastic, but golden gate stop/start in my env. doesn't work.

    ReplyDelete

Leave a Reply...