When you run crs_stat -t command, you can see at below format output
Name Type Target State Host
------------------------------------------------------------
ora.test.db application ONLINE ONLINE server01
ora....e1.inst application ONLINE ONLINE server01
ora....e2.inst application ONLINE ONLINE server02
ora....SM1.asm application ONLINE ONLINE server01
ora....02.lsnr application ONLINE ONLINE server01
ora.server01.gsd application ONLINE ONLINE server01
ora.server01.ons application ONLINE ONLINE server01
ora.server01.vip application ONLINE ONLINE server01
ora....SM2.asm application ONLINE ONLINE server02
ora....02.lsnr application ONLINE ONLINE server02
ora.server02.gsd application ONLINE ONLINE server02
ora.server02.ons application ONLINE ONLINE server02
ora.server02.vip application ONLINE ONLINE server02
Here is readable format output.
Run below code in shell script
#!/usr/bin/ksh
#
# Sample 10g 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
export ORA_CRS_HOME=/home/oracle/oracle/product/10.1/crs
QSTAT=-u
AWK=/usr/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:
$ORA_CRS_HOME/bin/crs_stat $QSTAT | $AWK \
'BEGIN { 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;}'
Here is output
HA Resource Target State
----------- ------ -----
ora.test.db ONLINE ONLINE on server01
ora.neptune.test1.inst ONLINE ONLINE on server01
ora.neptune.test2.inst ONLINE ONLINE on server02
ora.server01.ASM1.asm ONLINE ONLINE on server01
ora.server01.LISTENER_server01.lsnr ONLINE ONLINE on server01
ora.server01.gsd ONLINE ONLINE on server01
ora.server01.ons ONLINE ONLINE on server01
ora.server01.vip ONLINE ONLINE on server01
ora.server02.ASM2.asm ONLINE ONLINE on server02
ora.server02.LISTENER_server02.lsnr ONLINE ONLINE on server02
ora.server02.gsd ONLINE ONLINE on server02
ora.server02.ons ONLINE ONLINE on server02
ora.server02.vip ONLINE ONLINE on server02
Name Type Target State Host
------------------------------------------------------------
ora.test.db application ONLINE ONLINE server01
ora....e1.inst application ONLINE ONLINE server01
ora....e2.inst application ONLINE ONLINE server02
ora....SM1.asm application ONLINE ONLINE server01
ora....02.lsnr application ONLINE ONLINE server01
ora.server01.gsd application ONLINE ONLINE server01
ora.server01.ons application ONLINE ONLINE server01
ora.server01.vip application ONLINE ONLINE server01
ora....SM2.asm application ONLINE ONLINE server02
ora....02.lsnr application ONLINE ONLINE server02
ora.server02.gsd application ONLINE ONLINE server02
ora.server02.ons application ONLINE ONLINE server02
ora.server02.vip application ONLINE ONLINE server02
Here is readable format output.
Run below code in shell script
#!/usr/bin/ksh
#
# Sample 10g 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
export ORA_CRS_HOME=/home/oracle/oracle/product/10.1/crs
QSTAT=-u
AWK=/usr/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:
$ORA_CRS_HOME/bin/crs_stat $QSTAT | $AWK \
'BEGIN { 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;}'
Here is output
HA Resource Target State
----------- ------ -----
ora.test.db ONLINE ONLINE on server01
ora.neptune.test1.inst ONLINE ONLINE on server01
ora.neptune.test2.inst ONLINE ONLINE on server02
ora.server01.ASM1.asm ONLINE ONLINE on server01
ora.server01.LISTENER_server01.lsnr ONLINE ONLINE on server01
ora.server01.gsd ONLINE ONLINE on server01
ora.server01.ons ONLINE ONLINE on server01
ora.server01.vip ONLINE ONLINE on server01
ora.server02.ASM2.asm ONLINE ONLINE on server02
ora.server02.LISTENER_server02.lsnr ONLINE ONLINE on server02
ora.server02.gsd ONLINE ONLINE on server02
ora.server02.ons ONLINE ONLINE on server02
ora.server02.vip ONLINE ONLINE on server02