美化oracle 10g crs_stat结果

crs_stat命令通常在结果中Name部分被截断,难以配置到resource Name的全称。

#crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora....tdb1.cs application    ONLINE    ONLINE    node2
ora....db1.srv application    ONLINE    ONLINE    node1
ora....tdb2.cs application    ONLINE    ONLINE    node2

美化方法如下:

把以下脚本放在$ORA_CRS_HOME/bin下,文件名为crs_status。
文件用户所属改为oracle用户,权限改为755。

执行crs_status即可。

#!/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
QSTAT=-u
AWK=/bin/awk    # if not available use /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;}'

执行结果如下:

#crs_status
HA Resource                               Target     State
-------------------------------           ------     ----------------
ora.orcl.SRV_node1.cs                     ONLINE     ONLINE on node2
ora.orcl.SRV_node1.node1.srv              ONLINE     ONLINE on node1
ora.orcl.SRV_node2.cs                     ONLINE     ONLINE on node2
ora.orcl.SRV_node2.node2.srv              ONLINE     ONLINE on node2
ora.orcl.db                               ONLINE     ONLINE on node2
ora.orcl.node1.inst                       ONLINE     ONLINE on node1

你可能感兴趣的:(oracle,oracle,职场,10g,休闲,crs_stat)