环境:Linux 6.6 X64 + oracle 11g RAC
需求:运行crs_stat命令发现resource的名称不全,如果我需要查看某系resource的名称不方便。
如下所示,特别是name 和type列名称不全,有缩进。
[grid@racnode1 ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.DATADG.dg ora....up.type ONLINE ONLINE racnode1
ora.FREDG.dg ora....up.type ONLINE ONLINE racnode1
ora....ER.lsnr ora....er.type ONLINE ONLINE racnode1
ora....N1.lsnr ora....er.type ONLINE ONLINE racnode2
ora....N2.lsnr ora....er.type ONLINE ONLINE racnode1
ora....N3.lsnr ora....er.type ONLINE ONLINE racnode1
ora....TING.dg ora....up.type ONLINE ONLINE racnode1
ora.asm ora.asm.type ONLINE ONLINE racnode1
ora.asp.db ora....se.type ONLINE ONLINE racnode1
ora.cvu ora.cvu.type ONLINE ONLINE racnode1
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora....network ora....rk.type ONLINE ONLINE racnode1
ora.oc4j ora.oc4j.type ONLINE ONLINE racnode1
ora.ons ora.ons.type ONLINE ONLINE racnode1
ora....SM1.asm application ONLINE ONLINE racnode1
ora....E1.lsnr application ONLINE ONLINE racnode1
ora....de1.gsd application OFFLINE OFFLINE
ora....de1.ons application ONLINE ONLINE racnode1
ora....de1.vip ora....t1.type ONLINE ONLINE racnode1
ora....SM2.asm application ONLINE ONLINE racnode2
ora....E2.lsnr application ONLINE ONLINE racnode2
ora....de2.gsd application OFFLINE OFFLINE
ora....de2.ons application ONLINE ONLINE racnode2
ora....de2.vip ora....t1.type ONLINE ONLINE racnode2
ora.scan1.vip ora....ip.type ONLINE ONLINE racnode2
ora.scan2.vip ora....ip.type ONLINE ONLINE racnode1
ora.scan3.vip ora....ip.type ONLINE ONLINE racnode1
</pre><pre name="code" class="html">找了一段代码改下,代码如下,编辑后你放在root的bin下,用root就可以查了
</pre><pre name="code" class="html"><pre name="code" class="html">[root@racnode1 bin]# pwd
/bin
[root@racnode1 bin]# ll crsstat
-rwxr-xr-x. 1 root root 666 6月 30 13:55 crsstat
<span style="font-family: Arial, Helvetica, sans-serif;">[root@racnode1 bin]# cat crsstat </span>
<pre name="code" class="html">awk 'BEGIN {printf "%-36s %-26s %-10s %-10s %-10s \n","Name ","Type ","Target ","State ","Host "; printf "%-36s %-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 "%-36s %-26s %-10s %-10s %-10s\n", appname,apptype,apptarget,appstate,apphost; state=0;}'
<p>[root@racnode1 bin]# </p>
编辑好后,请赋权chmod +x crsstat
然后请再把gird用户环境变量中PATH中行 $ORACLE_HOME/bin放到root的环境变量中
<pre name="code" class="plain">
<pre name="code" class="plain">PATH=$PATH:$JAVA_HOME/bin:<span style="color:#ff0000;">/u01/app/11.2.0/grid/bin</span>
然后保存生效,看看结果
</pre><pre name="code" class="html"><pre name="code" class="plain">[root@racnode1 ~]# crsstat
Name Type Target State Host
----------------------------- -------------------- ---------- --------- ------- ora.DATADG.dg ora.diskgroup.type ONLINE ONLINE racnode1
ora.FREDG.dg ora.diskgroup.type ONLINE ONLINE racnode1
ora.LISTENER.lsnr ora.listener.type ONLINE ONLINE racnode1
ora.LISTENER_SCAN1.lsnr ora.scan_listener.type ONLINE ONLINE racnode2
ora.LISTENER_SCAN2.lsnr ora.scan_listener.type ONLINE ONLINE racnode1
ora.LISTENER_SCAN3.lsnr ora.scan_listener.type ONLINE ONLINE racnode1
ora.OCRVOTING.dg ora.diskgroup.type ONLINE ONLINE racnode1
ora.asm ora.asm.type ONLINE ONLINE racnode1
ora.asp.db ora.database.type ONLINE ONLINE racnode1
ora.cvu ora.cvu.type ONLINE ONLINE racnode1
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora.net1.network ora.network.type ONLINE ONLINE racnode1
ora.oc4j ora.oc4j.type ONLINE ONLINE racnode1
ora.ons ora.ons.type ONLINE ONLINE racnode1
ora.racnode1.ASM1.asm application ONLINE ONLINE racnode1
ora.racnode1.LISTENER_RACNODE1.lsnr application ONLINE ONLINE racnode1
ora.racnode1.gsd application OFFLINE OFFLINE
ora.racnode1.ons application ONLINE ONLINE racnode1
ora.racnode1.vip ora.cluster_vip_net1.type ONLINE ONLINE racnode1
ora.racnode2.ASM2.asm application ONLINE ONLINE racnode2
ora.racnode2.LISTENER_RACNODE2.lsnr application ONLINE ONLINE racnode2
ora.racnode2.gsd application OFFLINE OFFLINE
ora.racnode2.ons application ONLINE ONLINE racnode2
ora.racnode2.vip ora.cluster_vip_net1.type ONLINE ONLINE racnode2
ora.scan1.vip ora.scan_vip.type ONLINE ONLINE racnode2
ora.scan2.vip ora.scan_vip.type ONLINE ONLINE racnode1
ora.scan3.vip ora.scan_vip.type ONLINE ONLINE racnode1
[root@racnode1 ~]#
其实,oracle 11g开始oracle已经不推荐用crs_stat命令了,推荐用crsctl
</pre><pre name="code" class="html">crsctl stat res -t
</pre><pre name="code" class="html">[grid@racnode1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATADG.dg
ONLINE ONLINE racnode1
ONLINE ONLINE racnode2
ora.FREDG.dg
ONLINE ONLINE racnode1
ONLINE ONLINE racnode2
ora.LISTENER.lsnr
ONLINE ONLINE racnode1
ONLINE ONLINE racnode2
ora.OCRVOTING.dg
ONLINE ONLINE racnode1
ONLINE ONLINE racnode2
ora.asm
ONLINE ONLINE racnode1 Started
ONLINE ONLINE racnode2 Started
ora.gsd
OFFLINE OFFLINE racnode1
OFFLINE OFFLINE racnode2
ora.net1.network
ONLINE ONLINE racnode1
ONLINE ONLINE racnode2
ora.ons
ONLINE ONLINE racnode1
ONLINE ONLINE racnode2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE racnode2
ora.LISTENER_SCAN2.lsnr
1 ONLINE ONLINE racnode1
ora.LISTENER_SCAN3.lsnr
1 ONLINE ONLINE racnode1
ora.asp.db
1 ONLINE ONLINE racnode1 Open
2 ONLINE ONLINE racnode2 Open
ora.cvu
1 ONLINE ONLINE racnode1
ora.oc4j
1 ONLINE ONLINE racnode1
ora.racnode1.vip
1 ONLINE ONLINE racnode1
ora.racnode2.vip
1 ONLINE ONLINE racnode2
ora.scan1.vip
1 ONLINE ONLINE racnode2
ora.scan2.vip
1 ONLINE ONLINE racnode1
ora.scan3.vip
1 ONLINE ONLINE racnode1
这样就没上面的问题了。