Operating System - HP-UX
1748165 Members
4208 Online
108758 Solutions
New Discussion юеВ

Re: How to find if 3 databases are up and running from UNIX shell

 
Suman_7
Frequent Advisor

How to find if 3 databases are up and running from UNIX shell

I have to test for a condition whether the 3 oracle databases are up or not. Can you please suggest me an easy way to do it

Thanks
15 REPLIES 15
Jeff_Traigle
Honored Contributor

Re: How to find if 3 databases are up and running from UNIX shell

What database (Oracle, DB2, MySQL, Sybase, etc.)? Trying to check from the database server itself or from another system?
--
Jeff Traigle
Jeff_Traigle
Honored Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Nevermind... you said Oracle.

Can do it this way...

DBS="inst1 inst2 inst3"

#!/usr/bin/sh

for DATABASE in $DBS
do
tnsping inst1
done

(You'll want to check the syntax of that tnsping command... we don't run Oracle at my new job. It also assumes you have ${ORACLE_HOME} in your path.)
--
Jeff Traigle
Mobeen_1
Esteemed Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Suman,
It depends on how and from where you would like to check your database instances. For example, would you like to check from the host level or database level or ???

In any case, the following are some ways in which you can check

1. Ping the instance name (if there is a host entry for the instance)

2. Write a simple script that would log into
your database instance and check for the
dB availability

3. You could also monitor for the database
processes to determine the availability
of each of the database instance

regards
Mobeen
Jeff_Traigle
Honored Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Gee... I'm having a difficult time... the DBS definition shou,d of course, be after the shell specification.
--
Jeff Traigle
Suman_7
Frequent Advisor

Re: How to find if 3 databases are up and running from UNIX shell

The TNSPING gives :

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1546))) (CONNECT_DATA = (SID = )))
OK (40 msec)

DO I need to grep for OK?

Thanks

Sanjay_6
Honored Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Hi,

How about,

ps -ef |grep pmon |grep -v grep |wc -l

This should give "3" as the return value if the three oracle databases are running on the system.

Hope this helps.

Regds
Sundar_7
Honored Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Hi Suman,

You can try this

DBS="inst1 inst2 inst3"
for INST in $DBS
do
tnsping $INST 1>/dev/null 2>&1
if [[ $? -eq 0 ]]
then
echo "Instance $INST is running"
else
echo "Instance $INST is not running"
fi
done

The above example will work fine as long as tnsping is not failing for any other reason.

-- Sundar.
Learn What to do ,How to do and more importantly When to do ?
Anil C. Sedha
Trusted Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Suman,

Just grep for your oracle DB name by doing a ps -ef
edit a file in /etc/db and specify your dbnames in it. Save the file

for dbname in $(cat -v /etc/db)
ps -ef | grep dbname
if [ $? = 0 ]; then
echo "dbname database is up"
else
echo "dbname database is not running"
fi
done


-Anil
If you need to learn, now is the best opportunity
Anil C. Sedha
Trusted Contributor

Re: How to find if 3 databases are up and running from UNIX shell

Hit the submit button too quick

for dbname in $(cat -v /etc/db)
ps -ef | grep $dbname
if [ $? = 0 ]; then
echo "$dbname database is up"
else
echo "$dbname database is not running"
fi
done

-Anil
If you need to learn, now is the best opportunity