Friday, September 17, 2010

crs_stat in 11g

Check 11g Grid Status, shows RAC database Up/Down Status


#!/usr/bin/ksh
#  works on linux
# Description:
# - Returns formatted version of crs_stat -t, in tabular
# format, with the complete rsc names and filtering keywords
# - The argument, $RSC_KEY, is optional and if passed to the script, will
# limit the output to HA resources whose names match $RSC_KEY.
# Requirements:
# - $ORA_CRS_HOME should be set in your environment
# Modifications
# 5/2010 - use oraenv to set the environment, grid must be in oratab
# - check if search argument is null and substitute .* to create a valid syntax for Solaris
ORACLE_SID=grid;ORAENV_ASK=NO;. oraenv;ORAENV_ASK=YES
# If search argument is null, substitute .*, meaning match anything
if [[ -z $1 ]]; then
RSC_KEY='.*'
else
RSC_KEY=$1
fi
#QSTAT=-u
QSTAT=-l
AWK=/bin/awk
$ORACLE_HOME/bin/crs_stat $QSTAT | $AWK \
'BEGIN {printf "%-45s %-10s %-18s\n", "HA Resource", "Target", "State";
printf "%-45s %-10s %-18s\n", "-----------", "------", "-----";
FS="="; state = 0 }
$1~/NAME/ && $2~/'$RSC_KEY'/ { appname=$2; state=1}
state == 0 {next}
$1~/TARGET/ && state == 1 {apptarget = $2; state=2}
$1~/STATE/ && state == 2 {appstate = $2; state=3}
state == 3 {printf "%-45s %-10s %-18s\n", appname, apptarget, appstate; state=0}'