Script to get oracle database status UP or DOWN

Script to get oracle database status UP or DOWN.

This script verifies if the oratab file exists in /etc/ directory then the server is Linux or AIX and ORATAB variable will be assigned /etc/oratab . If oratab is  not it existing under /etc/ directory  means then server is Solaris and ORATAB variable will be assigned the path /var/opt/oracle/oratab.

This script sends mail with below subject .

Mail Subject: <Date> – DB down on oraix01

 

#Script name: db_check.sh
#!/bin/ksh
SERVER=`uname -a |awk ‘{print $2}’`
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
else
ORATAB=/var/opt/oracle/oratab
fi
echo “`date` ” > /u00/app/oracle/scripts/log/status.log
echo “Oracle Database(s) Status $SERVER :\n” >> /u00/app/oracle/scripts/log/status.log
db=`egrep -i “:Y|:N” $ORATAB | cut -d”:” -f1 | grep -v “\#” | grep -v “\*” |grep -v agent`
pslist=”`ps -ef | grep pmon`”
for i in $db ; do
echo “$pslist” | grep “ora_pmon_$i” > /dev/null 2>$1
if (( $? )); then
echo “Oracle Instance – $i: Down” >> /u00/app/oracle/scripts/log/status.log
else
echo “Oracle Instance – $i: Up” >> /u00/app/oracle/scripts/log/status.log
fi
done
grep -i Down /u00/app/oracle/scripts/log/status.log
if [ $? -eq 0 ]
then
mailx -s “`date` DB down on $SERVER” dbgrp@ajara.tech < /u00/app/oracle/scripts/log/status.log
fi

Parameters passed:

None

How to run Manually?

sh db_check.sh

Run from the crontab

00,15,30,45 *  * * *  /u00/app/oracle/scripts/db_check.sh  2>/dev/null

Explanation:

Case1:ORCLP — DB is running

pslist=”`ps -ef | grep pmon`”
$ i=ORCLP
$ echo “$pslist” | grep “ora_pmon_$i” > /dev/null 2>$1
$ echo $?
0
$if (( $? )); then ==> here it returns 0 , echo in the else part will execute . means DB is running -UP

Case2: PQR — DB is not running but entry is there in /etc/oratab

pslist=”`ps -ef | grep pmon`”
$ i=XYZ
$ echo “$pslist” | grep “ora_pmon_$i” > /dev/null 2>$1
$ echo $?
1
$if (( $? )); then ==> here it returns 1 , echo in the if part will execute . means DB is not running -DOWN

 

Sample output

Oracle Database(s) Status oraix01 :

Oracle Instance – ORCLP: Up
Oracle Instance – RMAN19C: Up
Oracle Instance – PQR: Down

 

See also: