Advertisement
BrokeDBA

check_crs.sh

Nov 10th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.41 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Version 1.0 - 4-5-2014  : Initial write
  4. # Version 1.1 - 2-8-2014  : Implemented Line Break feature by checking location of first and forth parameter
  5. #                           The following conditions are handled ( see <-- ... -> comments below )
  6. #                           index($0,$1)  > 32 means we get a line with STATE details only and we have a line break there:
  7. #                             ora.acfs_dg1.acfs_vol1.acfs
  8. #                                         ONLINE  OFFLINE      gract1                   admin unmounted /u01
  9. #                                                                                 <---   /acfs/acfs-vol1,STAB  -->  
  10. #                           index($0,$4) > 45 means we are missing server details for a Clustered resource
  11. #                             ora.asm
  12. #                                    1        ONLINE  OFFLINE             <- server_is_missing_here ->              STABLE
  13. #
  14. # Usage:  To display all resourcees     : $ ./crs
  15. #         To track a certain resource  :  $  watch ' crs | egrep "db|INST" '   <-- here <<db>> tracks all database resources
  16. #
  17. $GRID_HOME/bin/crsctl stat res -t  \
  18.   | awk -v t="$t" ' BEGIN { lres=0; cres= 0 } \
  19.      $0 !~ "----" && $0 !~ "TARGET" && $0 !~ "Cluster Resources" && $0 !~ "Local Resources" && $0 !~ "State details" \
  20.      { \
  21.        if (NF == 1 && ( $0 ~ "^ora" || $0  ~ "^My")) { \
  22.          rs=$0; \
  23.          #printf("\nRS: %s \n", rs); \
  24.        }  \
  25.        else { \
  26.          if ($1 ~ "^[0-9]") \
  27.            { \
  28.            # We found an Instance ID -> Global resource \
  29.            if ( cres == 0 ) \
  30.               { \
  31.            printf("\n*****  Cluster Resources: *****"); \
  32.               printf("\n%-27s %-3s   %-12s %-12s %-15s %s","Resource NAME", "INST", "TARGET","STATE", "SERVER","STATE_DETAILS"); \
  33.               printf("\n--------------------------- ----   ------------ ------------ --------------- -----------------------------------------"); \
  34.               }  \
  35.            cres++; \
  36.            idx = index($0,$1);
  37.                  # This is a tricky one - if are in APPEND mit idx should be > 60
  38.                  # The status messages like OFFLINE / ONLINE start at index 16 - so lets use 32 to be safe
  39.            idx = index($0,$1); \
  40.                  # Here we check wether wet some Node information or thie field is empty like instance or service down
  41.            idx4 = index($0,$4); \
  42.            # printf("\n Index4: %d ", idx4 );
  43.         if ( idx < 32   ) \
  44.              { \
  45.                # printf("Index: %d - Search:  %s --  %s " , idx, $1 , $0 );
  46.                if ( idx4 < 45 ) \
  47.                   printf ( "\n%-30s %-3s %-12s %-12s %-15s %s %s %s", rs, $1, $2, $3, $4, $5, $6,  $7 ); \
  48.         else \
  49.                   printf ( "\n%-30s %-3s %-12s %-12s %-15s %s %s %s", rs, $1, $2, $3, "-", $4, $5,  $6 ); \
  50.               } \
  51.            else { \
  52.               line1=$0; \
  53.               # remove leading spaces \
  54.               gsub(/^[ \t]+/, "", line1);
  55.               printf ( "%s", line1 );
  56.               } \
  57.            } \
  58.          else { \
  59.               # We found no Instance ID -> local resource
  60.            if ( lres == 0 ) \
  61.               { \
  62.            printf("*****  Local Resources: *****"); \
  63.               printf ("\n%-30s %-10s %-15s %-12s %-36s", "Rescource NAME", "TARGET", "STATE", "SERVER", "STATE_DETAILS");
  64.               printf ("\n%-30s %-10s %-15s %-12s %-36s", "-------------------------", "----------", "----------", "------------", "------------------");
  65.               } \
  66.            lres++; \
  67.                  # This is a tricky one - if are in APPEND mit idx should be > 60  
  68.                  # The status messages like OFFLINE / ONLINE start at index 16 - so lets use 32 to be safe
  69.            idx = index($0,$1); \
  70.                  # Here we check wether wet some Node information or thie field is empty like instance or service down
  71.         if ( idx < 32   ) \
  72.              { \
  73.                # printf("Index: %d - Search:  %s --  %s " , idx, $1 , $0 );
  74.                printf ( "\n%-30s %-10s %-15s %-12s %s %s %s %s", rs, $1, $2, $3, $4, $5, $6,  $7 ); \
  75.               } \
  76.            else { \
  77.               line1=$0; \
  78.               # remove leading spaces \
  79.               gsub(/^[ \t]+/, "", line1);
  80.               printf ( "%s", line1 );
  81.               } \
  82.          } \
  83.        } \
  84.      }
  85.  END { printf ( "\n\n" );  } \
  86.  '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement