Format output of crsctl status for RAC 11gR2 (and now 12c)

crs_stat -t in 10g was great because you could just print it out and grep for OFFLINE or UNKNOWN to determine if there was a problem.  11g deprecated the use of crs_stat -t.  It’s not just that you shouldn’t use it because it will be removed in a future release, it also will print OFFLINE for some components that will never be ONLINE.

As such, I wrote the following to print a format for 11g crsctl that will show it to you in a “greppable” format 🙂

#!/bin/sh

CRS_HOME=/u01/app/11.2.0/grid

awk 'BEGIN {printf "%-45s %-10s %-15s %-12s %-16s\n", "NAME", "TARGET", "STATE", "SERVER", "STATE_DETAILS"}'
awk 'BEGIN {printf "%-45s %-10s %-15s %-12s %-16s\n", "-------------------------", "----------", "----------", "------------", "------------------"}'
$CRS_HOME/bin/crsctl stat res -t \
  | awk -v t="$t" '$0 !~ "----" && $0 !~ "TARGET" && $0 !~ "Cluster Resources" && $0 !~ "Local Resources" \
      {
        if (NF == 1) {\
          rs=$0\
        } \
        else { \
          if ($1 ~ "^[0-9]") { \
            if ($0 ~ "Shutdown" || (rs ~ "svc$" && $3 == "OFFLINE" )) { \
              l = "$CRS_HOME/olsnodes -n"
              cmd[NR] = l
              while (l | getline line) {
                split(line,r," ")
                if (r[2] == $1) {
                  NODE = r[1]
                }
              }
              printf "%-45s %-10s %-15s %-12s %s %s\n", rs, $2, $3, NODE, $4, $5, "", $6, $7 \
            } \
            else { \
              printf "%-45s %-10s %-15s %-12s %s %s\n", rs, $2, $3, $4, $5, $6, $7 \
            } \
          } \
          else { \
            printf "%-45s %-10s %-15s %-12s %s %s\n", rs, $1, $2, $3, $4, $5, $6, $7 \
          } \
        } \
      }'

This will produce output such as below…

NAME                           TARGET     STATE           SERVER       STATE_DETAILS
-------------------------      ---------- ----------      ------------ ------------------
ora.ISCSI.dg                   ONLINE     ONLINE          dell11gr1
ora.ISCSI.dg                   ONLINE     ONLINE          dell11gr2
ora.LISTENER.lsnr              ONLINE     ONLINE          dell11gr1
ora.LISTENER.lsnr              ONLINE     ONLINE          dell11gr2
ora.asm                        ONLINE     ONLINE          dell11gr1    Started
ora.asm                        ONLINE     ONLINE          dell11gr2    Started
ora.gsd                        ONLINE     ONLINE          dell11gr1
ora.gsd                        ONLINE     ONLINE          dell11gr2
ora.net1.network               ONLINE     ONLINE          dell11gr1
ora.net1.network               ONLINE     ONLINE          dell11gr2
ora.ons                        ONLINE     ONLINE          dell11gr1
ora.ons                        ONLINE     ONLINE          dell11gr2
ora.LISTENER_SCAN1.lsnr        ONLINE     ONLINE          dell11gr2
ora.LISTENER_SCAN2.lsnr        ONLINE     ONLINE          dell11gr1
ora.LISTENER_SCAN3.lsnr        ONLINE     ONLINE          dell11gr2
ora.apptest.batch.svc          ONLINE     ONLINE          dell11gr2
ora.apptest.db                 ONLINE     ONLINE          dell11gr1    Open
ora.apptest.db                 ONLINE     ONLINE          dell11gr2    Open
ora.apptest.online.svc         ONLINE     ONLINE          dell11gr1
ora.cvu                        ONLINE     ONLINE          dell11gr2
ora.dell11gr1.vip              ONLINE     ONLINE          dell11gr1
ora.dell11gr2.vip              ONLINE     ONLINE          dell11gr2
ora.oc4j                       ONLINE     ONLINE          dell11gr2
ora.scan1.vip                  ONLINE     ONLINE          dell11gr2
ora.scan2.vip                  ONLINE     ONLINE          dell11gr1
ora.scan3.vip                  ONLINE     ONLINE          dell11gr2

UPDATE: 2017/06/23

This reflects the format for 12c

#!/bin/sh

CRS_HOME=/u01/app/12.1.0.2/grid

$CRS_HOME/bin/crsctl stat res -t \
  | awk -v t="$t" '$0 !~ "Cluster Resources" && $0 !~ "Local Resources" \
      { \
        if ($0 ~ "Name") { \
          printf "%-45s %-10s %-15s %-14s %s %s\n", $1, $2, $3, $4, $5, $6
          while (++k <= 120) { \
            printf("-") \
          } \
          printf ("\n") \
        } \
        if (NF == 1) {\
          rs=$0 \
        } \
        else if (NR != 2) { \
          if ($1 ~ "^[0-9]") { \
            if ($0 ~ "Shutdown" || (rs ~ "svc$" && $3 == "OFFLINE" )) { \
              l = "$CRS_HOME/olsnodes -n"
              cmd[NR] = l
              while (l | getline line) {
                split(line,r," ")
                if (r[2] == $1) {
                  NODE = r[1]
                }
              }
              printf "%-45s %-10s %-15s %-14s %s %s\n", rs, $2, $3, NODE, $4, $5, "", $6, $7 \
            } \
            else { \
              printf "%-45s %-10s %-15s %-14s %s %s\n", rs, $2, $3, $4, $5, $6, $7 \
            } \
          } \
          else { \
            printf "%-45s %-10s %-15s %-14s %s %s\n", rs, $1, $2, $3, $4, $5, $6, $7 \
          } \
        } \
      }'

13 comments for “Format output of crsctl status for RAC 11gR2 (and now 12c)

  1. Dave
    April 17, 2011 at 10:50 PM

    Thanks for the info.
    script works great!!!

  2. Ram
    August 29, 2011 at 10:49 AM

    This code is not working for me in solaris Can you please update the code ..?

  3. August 29, 2011 at 7:13 PM

    Hi Ram,

    What is the error? I would issue a man awk to see of the switches are different in Solaris.

    Regards,

    Steve

  4. Ram
    September 6, 2011 at 12:47 PM

    Yes it worked when i defined awk with AWK=/usr/xpg4/bin/awk # if not available use /usr/bin/awk .Thanks for the nice script …

  5. shashi
    September 21, 2011 at 2:21 AM

    Really good script . Makes job easy now.

  6. sachin
    January 31, 2012 at 10:37 PM

    Hi DEV IT WORKS REALY NICE WITH US.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.