crs_stat -t c’est pas toujours cool

Un petit script piqué à Jeff Hunter (www.ideveloppement.info) et un poil modifié afin d’obtenir l’état de toutes les ressources du Cluster. Plus sympa à lire qu’un crs_stat -t.

#!/bin/ksh

QSTAT=-u
AWK=/usr/bin/nawk

# +----------------------------------------------------------------------------+
# | TABLE HEADER |
# +----------------------------------------------------------------------------+

$AWK
'BEGIN {printf "%-45s %-10s %-18sn", "HA Resource", "Target", "State";
printf "%-45s %-10s %-18sn", "-----------", "------", "-----";}'

# +----------------------------------------------------------------------------+
# | TABLE BODY |
# +----------------------------------------------------------------------------+

$ORA_CRS_HOME/bin/crs_stat $QSTAT | $AWK
'BEGIN { FS="="; state = 0; }
$1~/NAME/ {appname = $2; state=1;}
$1~/TARGET/ && state == 1 {apptarget = $2; state=2;}
$1~/STATE/ && state == 2 {appstate = $2; state=3;}
state == 3 {printf "%-45s %-10s %-18sn", appname, apptarget, appstate; state=0;}
state == 0 {next;}'

Résultat :

HA Resource                                   Target     State
----------- ------ -----
ora.TESTRAC.TESTRAC1.inst ONLINE ONLINE on rac01
ora.TESTRAC.TESTRAC2.inst ONLINE ONLINE on rac02
ora.TESTRAC.db ONLINE ONLINE on rac02
ora.TOTO.TOTO1.inst ONLINE ONLINE on rac01
ora.TOTO.TOTO2.inst ONLINE ONLINE on rac02
ora.TOTO.db ONLINE ONLINE on rac02
ora.rac01.ASM1.asm ONLINE ONLINE on rac01
ora.rac01.ASM_LIST_rac01.lsnr ONLINE ONLINE on rac01
ora.rac01.gsd ONLINE ONLINE on rac01
ora.rac01.ons ONLINE ONLINE on rac01
ora.rac01.vip ONLINE ONLINE on rac01
ora.rac02.ASM2.asm ONLINE ONLINE on rac02
ora.rac02.ASM_LIST_rac02.lsnr ONLINE ONLINE on rac02
ora.rac02.gsd ONLINE ONLINE on rac02
ora.rac02.ons ONLINE OFFLINE
ora.rac02.vip ONLINE ONLINE on rac02

Le script original auquel il faut passer en paramètre le nom de la ressource de laquelle on souhaite avoir l’état :

#!/bin/ksh

# +----------------------------------------------------------------------------+
# | Jeffrey M. Hunter |
# | jhunter@idevelopment.info |
# | www.idevelopment.info |
# |----------------------------------------------------------------------------|
# | Copyright (c) 1998-2008 Jeffrey M. Hunter. All rights reserved. |
# |----------------------------------------------------------------------------|
# | DATABASE : Oracle |
# | FILE : rac_crs_stat |
# | CLASS : UNIX Shell Scripts |
# | PURPOSE : This KSH script will query all CRS resources using the crs_stat |
# | script. The report will be a formatted version of the |
# | crs_stat -t command, but in tabular form with resource name |
# | and status. Filtering options are available by passing in a |
# | single string parameter to this script. This argument will be |
# | used to limit the output to HA resources whose names match |
# | that string. |
# | USAGE : rac_crs_stat.ksh [RESOURCE_KEY] |
# | NOTE : This script requires the environment $ORA_CRS_HOME to be set to |
# | your CRS installation. |
# | NOTE : As with any code, ensure to test this script in a development |
# | environment before attempting to run it in production. |
# +----------------------------------------------------------------------------+

# +----------------------------------------------------------------------------+
# | GLOBAL VARIABLES |
# +----------------------------------------------------------------------------+

RSC_KEY=$1
QSTAT=-u
AWK=/usr/bin/awk

# +----------------------------------------------------------------------------+
# | TABLE HEADER |
# +----------------------------------------------------------------------------+

$AWK
'BEGIN {printf "%-45s %-10s %-18sn", "HA Resource", "Target", "State";
printf "%-45s %-10s %-18sn", "-----------", "------", "-----";}'

# +----------------------------------------------------------------------------+
# | 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 %-18sn", appname, apptarget, appstate; state=0;}'