Script para verificar que la base esta arriba

El siguiente script permite verificar si una base de datos esta arriba, en caso que no este arriba(OPEN) entonces envia un email avisando que esta abajo.

Sintaxis:
chkdbup -d [oraclesid]

Ejemplo:
chkdbup -d DEVDB

#!/bin/ksh
#######################################################################
#                                                                      
# SCRIPT       : chkdbup                             
#                                                                
# DESCRIPTION  : This job will check if the database if up and running.
#                If there is an error it will send an email.
#                                                                
# INPUT FILES  : $DBA_BASE/init - configuration file       
#              : $ORATAB - oracle oratab file                    
#              : $DBA_BASE/.forward - email notification file        
#                                                                
# OUTPUT FILES : NONE       
#                                                                
# CALLED OBJECT: $SCRIPTS/switchdb.ksh - switches environment    
#                and variables to a specific SID.           
# ASSUMPTIONS  : none
#                                                                      
# SETUP INSTRUCTIONS : Need to switchdb first to a default.            
#                                                                      
# COMMAND LINE EXECUTION: chkdbup                       
#                                                                      
# EXAMPLE: chkdbup DEVDB                                         
#                                                                      
# RESTART INSTRUCTIONS: rerun script                                   
# SPECIAL CONSIDERATIONS: NONE                                         
#######################################################################
# Modification Log:                                                    
# Version Date        Name              Description                    
#######################################################################
# 1.0     28-Jul-2006 Delfino Nunez     Initial Creation               
#######################################################################

########################################################################
# FUNCTION   : showHelp
# DESCRIPTION: Print the help for using the script
########################################################################
function showHelp {
			echo " Argument      Description"
      echo " ------------  ----------------------------------------------"
      echo " -d [sid]      Oracle sid to check."
      echo " -h            This help."
}
########################################################################
# Main Program start here
########################################################################

#variable declaration
. $DBA_BASE/init
export SID=$1
BOXNAME=`uname -n`
MAILIDS=`cat $DBA_BASE/.forward`
export dbpass=`cat $PWDFILE`
export EMAILMSG=$TMP/chkdbup.txt

DATETIME=`date '+%Y-%m-%d-%T'`

#check parameters
if [ "$1" != "" ]
then
while [ "$#" != "0" ]
do
  case $1 in
    -d)
      shift
      if [ "$1" != "" ]; then
        export ORACLE_SID=$1
        shift
      fi
    ;;
    -h)
      showHelp
      exit 0;
    ;;
    *)
      echo "Bad argument: $1"
      showHelp

      exit 1;
    ;;
  esac
done
else
	showHelp
	exit 1
fi

if [ -a $EMAILMSG ]
then
	rm $EMAILMSG
fi

. $SCRIPTS/switchdb.ksh $ORACLE_SID
sqlplus -s /nolog > /dev/null 2>&1 <
    whenever sqlerror exit failure
    connect $dbpass
    select count(*) from dual;
    exit success
EOF

if [[ $? -ne 0 ]]
then
   echo "The following database is not open, please check this problem:\n" >> $EMAILMSG
	 echo "Instance: $ORACLE_SID" >> $EMAILMSG
	 mailx -s "WARNING The database is not open - $BOXNAME:$ORACLE_SID $DATETIME" $MAILIDS < $EMAILMSG
   exit 1
fi

El email seria similar al siguiente:
—–Original Message—–
From: Oracle DBA [mailto:oracle@server.com]
Sent: Friday, July 28, 2006 12:31 PM
To: Nunez, Delfino
Subject: WARNING The database is not open – DEVSERVER:DEVDB 2006-07-28-12:31:01

The following database is not open, please check this problem:

Instance: DEVDB

Se puede combinar con el siguiente script para que verifique todas las bases que estan en el servidor (oratab).

#!/bin/ksh
#######################################################################
#                                                                      
# SCRIPT       : all.chkdbup                             
#                                                                
# DESCRIPTION  : This script will call chkdbup script for all databases
#                                                                
# INPUT FILES  : $DBA_BASE/init - configuration file       
#                                                                
# OUTPUT FILES : NONE       
#                                                                
# CALLED OBJECT: all.chkdbup
# ASSUMPTIONS  : NONE
#                                                                      
# SETUP INSTRUCTIONS : Need to switchdb first to a default.            
#                                                                      
# COMMAND LINE EXECUTION:                   
#                                                                      
# EXAMPLE:                                        
#                                                                      
# RESTART INSTRUCTIONS: rerun script                                   
# SPECIAL CONSIDERATIONS: NONE                                         
#######################################################################
# Modification Log:                                                    
# Version Date        Name              Description                    
#######################################################################
# 1.0     27-Jun-2006 Delfino Nunez     Initial Creation               
#######################################################################

############################################################################
# MAIN PROGRAM STARTS HERE                                                  
############################################################################

. $HOME/dba/init
priority=1

if [ -f /var/opt/oracle/oratab ] 
then
   export ORATAB='/var/opt/oracle/oratab'
elif [ -f /etc/oratab ]
then
   export ORATAB='/etc/oratab'
else
# following code from Steve Larson
   FOUND_ORATAB=$( find / -name oratab 2>/dev/null | head -1 )
   if [ "$FOUND_ORATAB" ] && [ -f "$FOUND_ORATAB" ]
   then
       ORATAB="$FOUND_ORATAB"
   else
       exit 1
   fi
fi

if [ "$#" != "0" ]
then
    ORACLE_SID=$1
    shift
    export ORACLE_SID
else
    for ORACLE_SID in `awk -F: '$1 !~ /\#/ && $1 !~ /\*/ {print $1}' $ORATAB`
    do
        swdb $ORACLE_SID
        chkdbup $ORACLE_SID
    done
fi
  1. Leave a comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: