1.无type字段
[grid@rac01 tmp]$ more crs_stat.sh awk 'BEGIN {printf "%-30s %-10s %-10s %-10s ","Name ","Target ","State ","Host "; printf "%-30s %-10s %-10s %-10s ","------------------------------","----------", "---------","-------";}' /u01/grid/grid_home/11.2.0.4/bin/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 ", appname,apptarget,appstate,apphost; state=0;}' [grid@rac01 tmp]$
[grid@rac01 tmp]$ ./crs_stat.sh Name Target State Host ------------------------------ ---------- --------- ------- ora.DATA.dg ONLINE ONLINE rac01 ora.LISTENER.lsnr ONLINE ONLINE rac01 ora.LISTENER_SCAN1.lsnr ONLINE ONLINE rac02 ora.OCR.dg ONLINE ONLINE rac01 ora.REDO.dg ONLINE ONLINE rac01 ora.asm ONLINE ONLINE rac01 ora.cvu ONLINE ONLINE rac01 ora.gsd OFFLINE OFFLINE ora.net1.network ONLINE ONLINE rac01 ora.oc4j ONLINE ONLINE rac01 ora.ons ONLINE ONLINE rac01 ora.rac01.ASM1.asm ONLINE ONLINE rac01 ora.rac01.LISTENER_RAC01.lsnr ONLINE ONLINE rac01 ora.rac01.gsd OFFLINE OFFLINE ora.rac01.ons ONLINE ONLINE rac01 ora.rac01.vip ONLINE ONLINE rac01 ora.rac02.ASM2.asm ONLINE ONLINE rac02 ora.rac02.LISTENER_RAC02.lsnr ONLINE ONLINE rac02 ora.rac02.gsd OFFLINE OFFLINE ora.rac02.ons ONLINE ONLINE rac02 ora.rac02.vip ONLINE ONLINE rac02 ora.scan1.vip ONLINE ONLINE rac02 ora.slnngk.db ONLINE ONLINE rac01 ora.slnngk.service_s1.svc ONLINE ONLINE rac01 ora.slnngk.service_s2.svc ONLINE ONLINE rac02
2.有type字段
[grid@rac01 tmp]$ more crs_stat_type.sh awk 'BEGIN {printf "%-26s %-26s %-10s %-10s %-10s ","Name ","Type ","Target ","State ","Host "; printf "%-30s %-26s %-10s %-10s %-10s ","------------------------------","------- -------------------","----------", "---------","-------";}' /u01/grid/grid_home/11.2.0.4/bin/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 ", appname,apptype,apptarget,appstate,apphost; state=0;}' [grid@rac01 tmp]$
[grid@rac01 tmp]$ ./crs_stat_type.sh Name Type Target State Host ------------------------------ -------------------------- ---------- --------- ------- ora.DATA.dg ora.diskgroup.type ONLINE ONLINE rac01 ora.LISTENER.lsnr ora.listener.type ONLINE ONLINE rac01 ora.LISTENER_SCAN1.lsnr ora.scan_listener.type ONLINE ONLINE rac02 ora.OCR.dg ora.diskgroup.type ONLINE ONLINE rac01 ora.REDO.dg ora.diskgroup.type ONLINE ONLINE rac01 ora.asm ora.asm.type ONLINE ONLINE rac01 ora.cvu ora.cvu.type ONLINE ONLINE rac01 ora.gsd ora.gsd.type OFFLINE OFFLINE ora.net1.network ora.network.type ONLINE ONLINE rac01 ora.oc4j ora.oc4j.type ONLINE ONLINE rac01 ora.ons ora.ons.type ONLINE ONLINE rac01 ora.rac01.ASM1.asm application ONLINE ONLINE rac01 ora.rac01.LISTENER_RAC01.lsnr application ONLINE ONLINE rac01 ora.rac01.gsd application OFFLINE OFFLINE ora.rac01.ons application ONLINE ONLINE rac01 ora.rac01.vip ora.cluster_vip_net1.type ONLINE ONLINE rac01 ora.rac02.ASM2.asm application ONLINE ONLINE rac02 ora.rac02.LISTENER_RAC02.lsnr application ONLINE ONLINE rac02 ora.rac02.gsd application OFFLINE OFFLINE ora.rac02.ons application ONLINE ONLINE rac02 ora.rac02.vip ora.cluster_vip_net1.type ONLINE ONLINE rac02 ora.scan1.vip ora.scan_vip.type ONLINE ONLINE rac02 ora.slnngk.db ora.database.type ONLINE ONLINE rac01 ora.slnngk.service_s1.svc ora.service.type ONLINE ONLINE rac01 ora.slnngk.service_s2.svc ora.service.type ONLINE ONLINE rac02
-- The End --