11gR2 RAC – crsctl status resource script

Posted: November 20, 2013 in RAC

Nice script to tidy up the output of crsctl status resource

script

#!/usr/bin/ksh
#
# 11g CRS resource status query script
#
# 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

RSC_KEY=$1
QSTAT=-u
AWK=/bin/awk # if not available use /usr/bin/awk

# Table header:echo ""
$AWK \
'BEGIN {printf "%-45s %-10s %-18s\n", "HA Resource", "Target", "State";
printf "%-45s %-10s %-18s\n", "-----------", "------", "-----";}'

# Table body:
/u01/app/11.2.0.3/grid/bin/crsctl status resource | $AWK \
'
function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }

BEGIN { FS="="; state = 0; }
$1~/NAME/ && $2~/'$RSC_KEY'/ {appname = $2; state=1};
state == 0 {next;}
$1~/TARGET/ && state == 1 {apptarget = $2; split(apptarget, atarget, ","); state=2;}
$1~/STATE/ && state == 2 {appstate = $2; split(appstate, astate, ","); state=3;}
state == 3 { split(appname, a, ",");
for (i = 1; i <= length(atarget); i++) {
printf "%-45s %-10s %-18s\n", appname, trim(atarget[i]), trim(astate[i])
};
state=0;}'

Output Example

[oracle@dba01tst ~]$ ./crs_stat.ksh
HA Resource Target State
----------- ------ -----
ora.DATA.dg ONLINE ONLINE on dba01tst
ora.DATA.dg ONLINE ONLINE on dba02tst
ora.FLASH.dg ONLINE ONLINE on dba01tst
ora.FLASH.dg ONLINE ONLINE on dba02tst
ora.LISTENER.lsnr ONLINE ONLINE on dba01tst
ora.LISTENER.lsnr ONLINE ONLINE on dba02tst
ora.LISTENER_SCAN1.lsnr ONLINE ONLINE on dba02tst
ora.LISTENER_SCAN2.lsnr ONLINE ONLINE on dba01tst
ora.LISTENER_SCAN3.lsnr ONLINE ONLINE on dba01tst
ora.asm ONLINE ONLINE on dba01tst
ora.asm ONLINE ONLINE on dba02tst
ora.cvu ONLINE ONLINE on dba01tst
ora.dba01tst.vip ONLINE ONLINE on dba01tst
ora.dba02tst.vip ONLINE ONLINE on dba02tst
ora.dbatst.db ONLINE ONLINE on dba01tst
ora.dbatst.db ONLINE ONLINE on dba02tst
ora.dbatst.dbatstinst1.svc ONLINE ONLINE on dba01tst
ora.gsd OFFLINE OFFLINE
ora.gsd OFFLINE OFFLINE
ora.net1.network ONLINE ONLINE on dba01tst
ora.net1.network ONLINE ONLINE on dba02tst
ora.oc4j OFFLINE OFFLINE
ora.ons ONLINE ONLINE on dba01tst
ora.ons ONLINE ONLINE on dba02tst
ora.scan1.vip ONLINE ONLINE on dba02tst
ora.scan2.vip ONLINE ONLINE on dba01tst
ora.scan3.vip ONLINE ONLINE on dba01tst

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s