ORACLE RAC 集群命令crs_stat的显示格式太短了

 crs_stat -t
Name           Type           Target    State     Host        
------------------------------------------------------------
ora.DATA.dg    ora....up.type ONLINE    ONLINE    node1       
ora....ER.lsnr ora....er.type ONLINE    ONLINE    node1       
ora....N1.lsnr ora....er.type ONLINE    ONLINE    node2       
ora....N2.lsnr ora....er.type ONLINE    ONLINE    node1       
ora....N3.lsnr ora....er.type ONLINE    ONLINE    node1       
ora.OCR.dg     ora....up.type ONLINE    ONLINE    node1       
ora.VOTING.dg  ora....up.type ONLINE    ONLINE    node1       
ora.asm        ora.asm.type   ONLINE    ONLINE    node1       
ora.eons       ora.eons.type  ONLINE    ONLINE    node1       
ora.gsd        ora.gsd.type   OFFLINE   OFFLINE               
ora.lotest.db  ora....se.type ONLINE    ONLINE    node1       
ora....network ora....rk.type ONLINE    ONLINE    node1       
ora....SM1.asm application    ONLINE    ONLINE    node1       
ora....E1.lsnr application    ONLINE    ONLINE    node1       
ora.node1.gsd  application    OFFLINE   OFFLINE               
ora.node1.ons  application    ONLINE    ONLINE    node1       
ora.node1.vip  ora....t1.type ONLINE    ONLINE    node1       
ora....SM2.asm application    ONLINE    ONLINE    node2       
ora....E2.lsnr application    ONLINE    OFFLINE               
ora.node2.gsd  application    OFFLINE   OFFLINE               
ora.node2.ons  application    ONLINE    ONLINE    node2       
ora.node2.vip  ora....t1.type ONLINE    ONLINE    node2       
ora.oc4j       ora.oc4j.type  OFFLINE   OFFLINE               
ora.ons        ora.ons.type   ONLINE    ONLINE    node1       
ora....ry.acfs ora....fs.type ONLINE    ONLINE    node1       
ora.scan1.vip  ora....ip.type ONLINE    ONLINE    node2       
ora.scan2.vip  ora....ip.type ONLINE    ONLINE    node1       
ora.scan3.vip  ora....ip.type ONLINE    ONLINE    node1   

可以直观的列出各节点进程的状态。 但是这个命令的不足之处,就是Name列,不能显示全,那么在使用的时候就有点不方便。比如我们启动和关闭相关进程的时候。

 比如:crs_start ora.node2.LISTENER_NODE2.lsnr

--我们这里要写全进程的名称,如果名称过长,就不能显示全。

其实这个脚本不够是把crs_stat 显示 行转列下而已。

那么我们来修理下ORACLE公司开发人员,这群丫的拿了钱,做的不咋友好。不就是脚本嘛! 我们DIY去。。。。

##10g上使用
awk  ‘BEGIN {printf "%-30s %-10s %-10s %-10s \n","Name                          ","Target    ","State     ","Host   "; printf "%-30s %-10s %-10s %-10s\n","------------------------------","----------", "---------","-------";}‘
crs_stat | awk ‘BEGIN { FS="=| ";state = 0;}  $1~/NAME/ {appname = $2; state=1};  state == 0 {next;}  $1~/TARGET/ && state == 1 {apptarget = $2; state=2;} $1~/STATE/ && state == 2 {appstate = $2; apphost = $4; state=3;} state == 3 {printf "%-30s %-10s %-10s %-10s\n", appname,apptarget,appstate,apphost; state=0;}‘

##11g 上使用
awk  ‘BEGIN {printf "%-30s %-26s %-10s %-10s %-10s \n","Name                          ","Type                      ","Target    ","State     ","Host   "; printf "%-30s %-26s %-10s %-10s %-10s\n","-----------------------------------","--------------------------","----------", "---------","-------";}‘
crs_stat | 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; apphost = $4; state=4;} state == 4 {printf "%-30s %-26s %-10s %-10s %-10s\n", appname,apptype,apptarget,appstate,apphost; state=0;}‘
猩猩酷酷找到了上面两个脚本。本来在大名顶顶Davi 也有一篇 http://blog.****.net/tianlesoftware/article/details/6269010
不过这位老兄的脚本awk 后面带了个"/" 在redhat linux 5.3 x64下 老是报错. 兄弟我不才,awk不懂! linux下很多东西太复杂,太难学,太难记忆了。
所以大家还是用上面两个脚本。各位把上面脚本放进VI编辑器时候注意换行符\n\r,知道大家都喜欢COPY TO。把脚本的换行删除掉,变成2行。
awk ‘BEGIN.................
crs_stat | awk ‘BEGIN...........

我们vi crstat.sh  编辑完后。mv crstat.sh crstat

付权限 chmod a+x crstat

然后切换成root用户下 cp crstat /bin 这样让root grid 用户都可以使用。

为了让oracle 用户也用上 vi ~/.bash_profile  添加

export GRID_BIN=/...........----grid用的 bin    主要是调用crs_stat命令 可以在grid用下which它下

这样我们就很爽了 随时随地敲入 crstat 就显示

[oracle@node1 dbscripts]$ crstat
Name                                Type                           Target     State      Host       
----------------------------------- ------------------------------ ---------- ---------  -------   
ora.DATA.dg                         ora.diskgroup.type             ONLINE     ONLINE     node1     
ora.LISTENER.lsnr                   ora.listener.type              ONLINE     ONLINE     node1     
ora.LISTENER_SCAN1.lsnr             ora.scan_listener.type         ONLINE     ONLINE     node2     
ora.LISTENER_SCAN2.lsnr             ora.scan_listener.type         ONLINE     ONLINE     node1     
ora.LISTENER_SCAN3.lsnr             ora.scan_listener.type         ONLINE     ONLINE     node1     
ora.OCR.dg                          ora.diskgroup.type             ONLINE     ONLINE     node1     
ora.VOTING.dg                       ora.diskgroup.type             ONLINE     ONLINE     node1     
ora.asm                             ora.asm.type                   ONLINE     ONLINE     node1     
ora.eons                            ora.eons.type                  ONLINE     ONLINE     node1     
ora.gsd                             ora.gsd.type                   OFFLINE    OFFLINE              
ora.lotest.db                       ora.database.type              ONLINE     ONLINE     node1     
ora.net1.network                    ora.network.type               ONLINE     ONLINE     node1     
ora.node1.ASM1.asm                  application                    ONLINE     ONLINE     node1     
ora.node1.LISTENER_NODE1.lsnr       application                    ONLINE     ONLINE     node1     
ora.node1.gsd                       application                    OFFLINE    OFFLINE              
ora.node1.ons                       application                    ONLINE     ONLINE     node1     
ora.node1.vip                       ora.cluster_vip_net1.type      ONLINE     ONLINE     node1     
ora.node2.ASM2.asm                  application                    ONLINE     ONLINE     node2     
ora.node2.LISTENER_NODE2.lsnr       application                    ONLINE     OFFLINE              
ora.node2.gsd                       application                    OFFLINE    OFFLINE              
ora.node2.ons                       application                    ONLINE     ONLINE     node2     
ora.node2.vip                       ora.cluster_vip_net1.type      ONLINE     ONLINE     node2     
ora.oc4j                            ora.oc4j.type                  OFFLINE    OFFLINE              
ora.ons                             ora.ons.type                   ONLINE     ONLINE     node1     
ora.registry.acfs                   ora.registry.acfs.type         ONLINE     ONLINE     node1     
ora.scan1.vip                       ora.scan_vip.type              ONLINE     ONLINE     node2     
ora.scan2.vip                       ora.scan_vip.type              ONLINE     ONLINE     node1     
ora.scan3.vip                       ora.scan_vip.type              ONLINE     ONLINE     node1  


ORACLE RAC 集群命令crs_stat的显示格式太短了

上一篇:Oracle 课程八之跟踪事件set event


下一篇:JavaScript