Friday, May 3, 2013

Script For Listing 11gR2 Cluster Resource Status in CRS_STAT Output Format

crs_stat -t is depreciated in 11gR2 and replaced with crsctl stat res -t. Following script could be used to generate resource status output in a format that is similar to crs_stat -t in 11gR1.
#!/bin/sh
# Sample 11gR2 CRS resource status query script
# gives output similar to crs_stat -t in 11gR1
# Asanga Pradeep

awk \
  'BEGIN {printf "%-35s %-25s %-18s %-18s\n", "Resource Name", "Type", "Target","State";
          printf "%-35s %-25s %-18s %-18s\n", "-----------", "------", "-------","--------";}'
crsctl stat res | egrep -w "NAME|TYPE|TARGET|STATE" | sed -e "s/   / /g" | awk \
 'BEGIN { FS="="; state = 0; }
  $1~/NAME/ {appname = $2; state=1};
  state == 0 {next;}
  $1~/TYPE/ && state == 1 {apptype = $2; state=2;}
  $1~/TARGET/ && state == 2 {apptarget = $2; state=3;}
  $1~/STATE/ && state == 3 {appstate = $2; state=4;}
  state == 4 {
split(apptarget,targetarray,", ");
x=length(targetarray);
split(appstate,statearray,", ");
for(ix=1;ix<=x;ix++)
printf "%-35s %-25s %-18s %-18s\n", appname, apptype,targetarray[ix], statearray[ix]; state=0;}'




Output
Resource Name                       Type                      Target             State
-----------                         ------                    -------            --------
ora.CLUSTERDG.dg                    ora.diskgroup.type        ONLINE             ONLINE on rac4
ora.CLUSTERDG.dg                    ora.diskgroup.type        ONLINE             ONLINE on rac5
ora.DATA.dg                         ora.diskgroup.type        ONLINE             ONLINE on rac4
ora.DATA.dg                         ora.diskgroup.type        ONLINE             ONLINE on rac5
ora.FLASH.dg                        ora.diskgroup.type        ONLINE             ONLINE on rac4
ora.FLASH.dg                        ora.diskgroup.type        ONLINE             ONLINE on rac5
ora.LISTENER.lsnr                   ora.listener.type         ONLINE             ONLINE on rac4
ora.LISTENER.lsnr                   ora.listener.type         ONLINE             ONLINE on rac5
ora.LISTENER_SCAN1.lsnr             ora.scan_listener.type    ONLINE             ONLINE on rac5
ora.asm                             ora.asm.type              ONLINE             ONLINE on rac4
ora.asm                             ora.asm.type              ONLINE             ONLINE on rac5
ora.cvu                             ora.cvu.type              OFFLINE            OFFLINE
ora.gsd                             ora.gsd.type              OFFLINE            OFFLINE
ora.gsd                             ora.gsd.type              OFFLINE            OFFLINE
ora.net1.network                    ora.network.type          ONLINE             ONLINE on rac4
ora.net1.network                    ora.network.type          ONLINE             ONLINE on rac5
ora.oc4j                            ora.oc4j.type             OFFLINE            OFFLINE
ora.ons                             ora.ons.type              ONLINE             ONLINE on rac4
ora.ons                             ora.ons.type              ONLINE             ONLINE on rac5
ora.rac11g2.db                      ora.database.type         ONLINE             ONLINE on rac4
ora.rac11g2.db                      ora.database.type         ONLINE             ONLINE on rac5
ora.rac11g2.test.svc                ora.service.type          ONLINE             ONLINE on rac4
ora.rac11g2.test.svc                ora.service.type          ONLINE             ONLINE on rac5
ora.rac4.vip                        ora.cluster_vip_net1.type ONLINE             ONLINE on rac4
ora.rac5.vip                        ora.cluster_vip_net1.type ONLINE             ONLINE on rac5
ora.registry.acfs                   ora.registry.acfs.type    ONLINE             ONLINE on rac4
ora.registry.acfs                   ora.registry.acfs.type    ONLINE             ONLINE on rac5
ora.scan1.vip                       ora.scan_vip.type         ONLINE             ONLINE on rac5

Related Post
Script to get full name of the resources from crs_stat

Update 13 May 2013
In the above script both state and host name are in the same column. Below script will have a separate column for state and hostname
#!/bin/sh
# Sample 11gR2 CRS resource status query script
# gives output similar to crs_stat -t in 11gR1
# Asanga Pradeep

awk \
  'BEGIN {printf "%-35s %-25s %-18s %-18s %-18s\n", "Resource Name", "Type", "Target","State","Host";
          printf "%-35s %-25s %-18s %-18s %-18s\n", "-------------", "------", "-------","--------","----------";}'
crsctl stat res | egrep -w "NAME|TYPE|TARGET|STATE" | sed -e "s/   / /g" | awk \
 'BEGIN { FS="="; state = 0; }
  $1~/NAME/ {appname = $2; state=1};
  state == 0 {next;}
  $1~/TYPE/ && state == 1 {apptype = $2; state=2;}
  $1~/TARGET/ && state == 2 {apptarget = $2; state=3;}
  $1~/STATE/ && state == 3 {appstate = $2; state=4;}
  state == 4 {
split(apptarget,targetarray,", ");
x=length(targetarray);
split(appstate,statearray,", ");
  for(ix=1;ix<=x;ix++){
  split(statearray[ix],statehostarray," ");
  printf "%-35s %-25s %-18s %-18s %-18s\n", appname, apptype,targetarray[ix], statehostarray[1], statehostarray[3]; state=0;}

}'
Output
Resource Name                       Type                      Target             State              Host
-------------                       ------                    -------            --------           ----------
ora.CLUSTER_DG.dg                   ora.diskgroup.type        ONLINE             ONLINE             rhel6m1
ora.CLUSTER_DG.dg                   ora.diskgroup.type        ONLINE             ONLINE             rhel6m2
ora.DATA.dg                         ora.diskgroup.type        ONLINE             ONLINE             rhel6m1
ora.DATA.dg                         ora.diskgroup.type        ONLINE             ONLINE             rhel6m2
ora.FLASH.dg                        ora.diskgroup.type        ONLINE             ONLINE             rhel6m1
ora.FLASH.dg                        ora.diskgroup.type        ONLINE             ONLINE             rhel6m2
ora.MYLISTENER.lsnr                 ora.listener.type         ONLINE             ONLINE             rhel6m1
ora.MYLISTENER.lsnr                 ora.listener.type         ONLINE             ONLINE             rhel6m2
ora.MYLISTENER_SCAN1.lsnr           ora.scan_listener.type    ONLINE             ONLINE             rhel6m1
ora.asm                             ora.asm.type              ONLINE             ONLINE             rhel6m1
ora.asm                             ora.asm.type              ONLINE             ONLINE             rhel6m2
ora.cvu                             ora.cvu.type              ONLINE             ONLINE             rhel6m1
ora.gsd                             ora.gsd.type              OFFLINE            OFFLINE
ora.gsd                             ora.gsd.type              OFFLINE            OFFLINE
ora.net1.network                    ora.network.type          ONLINE             ONLINE             rhel6m1
ora.net1.network                    ora.network.type          ONLINE             ONLINE             rhel6m2
ora.oc4j                            ora.oc4j.type             ONLINE             ONLINE             rhel6m1
ora.ons                             ora.ons.type              ONLINE             ONLINE             rhel6m1
ora.ons                             ora.ons.type              ONLINE             ONLINE             rhel6m2
ora.registry.acfs                   ora.registry.acfs.type    ONLINE             ONLINE             rhel6m1
ora.registry.acfs                   ora.registry.acfs.type    ONLINE             ONLINE             rhel6m2
ora.rhel6m1.vip                     ora.cluster_vip_net1.type ONLINE             ONLINE             rhel6m1
ora.rhel6m2.vip                     ora.cluster_vip_net1.type ONLINE             ONLINE             rhel6m2
ora.scan1.vip                       ora.scan_vip.type         ONLINE             ONLINE             rhel6m1
ora.std11g2.db                      ora.database.type         ONLINE             ONLINE             rhel6m1
ora.std11g2.db                      ora.database.type         ONLINE             ONLINE             rhel6m2
ora.std11g2.myservice.svc           ora.service.type          ONLINE             ONLINE             rhel6m1
ora.std11g2.myservice.svc           ora.service.type          ONLINE             ONLINE             rhel6m2