Category Archives: Oracle Monitoring Scripts

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