Shell Script: Check Database is UP/DOWN

#!/bin/bash

#Setup Environment
export ORACLE_HOME=/home/oracle/product/11.2.0.3/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=sid1
export HNAME=`uname -n`

#Check pmon process
check_stat=`ps -ef|grep ${ORACLE_SID}|grep pmon|wc -l`;
if [ “$check_stat” -lt  “1” ]
then
#On some platforms, you can use mailx instead of mail
echo “Please contact Duty DBA ASAP” | mail -s “URGENT: $ORACLE_SID is down on $HNAME!” nravi3@gmail.com
exit 1
fi

# Check DB Connection
$ORACLE_HOME/bin/sqlplus / as sysdba<<! > /tmp/dbchk_$ORACLE_SID.ora
select * from v\$database;
exit
!

#*************************************************************
# If not, exit and e-mail . . .
#*************************************************************
check_stat=`cat /tmp/dbchk_$ORACLE_SID.ora|grep -i error|wc -l`;

if [ “$check_stat”  -ne  “0” ]
then
echo “Please contact Duty DBA ASAP” | mail -s “URGENT: $ORACLE_SID is down on $HNAME!” nravi3@gmail.com
exit 2
fi

 

Thanks,
Ravi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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: