SCRIPT TO VIEW WHICH DATABASE INSTANCE IS RUNNING CURRENTLY

SCRIPT TO VIEW WHICH DATABASE INSTANCE IS RUNNING

In this tutorial, we going to learn about to find which database instance is running now.

Mostly we use “/etc/oratab” to view what our database is running currently. Here, we going to use the script, by running of script file we can get the details of the database that is running currently.

Step 1: Check in the oratab and ensure which database is running and how many database is there.

$ cat /etc/oratab

oradb1:/u01/app/oracle/product/8.1.7:Y

oradb2:/u01/app/oracle/product/8.1.7:Y

oradb3:/u01/app/oracle/product/8.1.7:N

oradb4:/u01/app/oracle/product/8.1.7:Y

Step 2: Create the script file to find the running database instance

Vi oratab.sh

ORATAB=/etc/oratab

echo “`date`   ”

echo  “Oracle Database(s) Status `hostname` :\n”

db=`egrep -i “:Y|:N” $ORATAB | cut -d”:” -f1 | grep -v “\#” | grep -v “\*”`

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”

Else

{

{

echo “Oracle Instance – $i:       Up”

}

}

fi

done

Step 3: Give permission to that script file.

# chmod 744 oratab.sh

# ls -l oratab.sh

-rwxr–r–   1 oracle     dba     657 Mar  5 22:59 oratab.sh*

Step 4: Run the script and get the output

$ oratab.sh

Wed Feb  3 10:44:12 IST 2021

Oracle Database(s) Status for DBHOST server:

Oracle Instance – oradb1:   Up

Oracle Instance – oradb2:   Up

Oracle Instance – oradb3:   Down

Oracle Instance – oradb4:   Up

Recent Posts