miƩrcoles, 14 de diciembre de 2011

Checking the status of an Oracle Instance in Unix

In many Unix script is very common to find the commands below to check the status of an Oracle Instance :

_status=`ps -fe | grep pmon_${ORACLE_SID} | grep -v grep | wc -l`

This usually is correct. If the database is Up then it will return 1, else it returns 0.

But what happens if there's two instances in the same server. One named ORCL and the other ORC. In this case the command will return 2 when both databases are Up.

A posible solution to avoid a mistaken behavior in the script when asking "if [ ${_status} -eq 1 ]; then", is to check the status of the process relative to the specific instance. It can be done this way:

_status=`ps -fe | grep pmon_${ORACLE_SID} | grep -v grep | awk '{ print $NF"*" }' | grep pmon_${ORACLE_SID}"*" | wc -l`

With the commands above it will always return 0 or 1.

No hay comentarios: