Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Oracle RAC crs_stat enhancement
Hi all,
I am new to ksh so please point out any glaring mistakes in this script. Also this is just a base and I have not completed it but it should help some people I hope.
Situation:
crs_stat outputs way too much info in a less than desirable format.
Also crs_stat -t truncates information making administration somewhat
difficult. Also restarting many individual serices on a RAC node can
be error prone. So I wrote a script taking some aspects from a script
on metalink
Script:
#!/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: awk ORA_CRS_HOME
RSC_KEY=$1
QSTAT=-u
AWK=/usr/bin/awk # if not available use /usr/bin/awk
# Table header:echo ""
header()
{
$AWK \ 'BEGIN {printf "%-45s %-10s %-18s\n", "HA Resource", "Target", "State"; printf "%-45s %-10s %-18s\n", "-----------", "------", "-----";}'}
# Table body:
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;}'
# Start Scripts
startups()
{
echo " " echo " " body | $AWK ' BEGIN { print "svrctl commands to start up OFFLINE services" } /OFFLINE/ { split($1, a, ".") for (i in a) { if (a[i] == "lsnr") print "srvctl start nodeapps -n "a[2] if (a[i] == "asm") { print "ASM instance is down this is bad" print "srvctl start asm -n "a[2] } if (a[i] == "db") print "srvctl start database -d "a[2] if (a[i] == "inst") { print "Instance "a[3]" is down to restart:" print "srvctl start instance -d "a[2]" -i "a[3] } } } END { print "End of srvctl commands"} '
###############
# Main
###############
# - $ORA_CRS_HOME should be set in your environment
# I used 5 as an arbitrary number there is probably a better way but
this works
if [[ `echo ${ORA_CRS_HOME} |wc -k -c` -gt 5 ]]; then
echo "OK CRS_HOME is set"
else
echo "ORA_CRS_HOME env var not set" echo "Please set ORA_CRS_HOME and rerun" exit 20
header
body
startups
############### End of Script ###################
################### Output ####################
OK CRS_HOME is set
HA Resource Target State ----------- ------ ----- ora.ODSBLPR.ODSBLPR1.inst ONLINE ONLINE on iedm3303da ora.ODSBLPR.ODSBLPR2.inst ONLINE ONLINE on iedm3304da ora.ODSBLPR.db ONLINE ONLINE on iedm3304da ora.ODSCDPR.ODSCDPR1.inst ONLINE ONLINE on iedm3303da ora.ODSCDPR.ODSCDPR2.inst ONLINE ONLINE on iedm3304da ora.ODSCDPR.db ONLINE ONLINE on iedm3304da ora.ODSCMPR.ODSCMPR1.inst ONLINE ONLINE on iedm3303da ora.ODSCMPR.ODSCMPR2.inst ONLINE ONLINE on iedm3304da ora.ODSCMPR.db ONLINE ONLINE on iedm3304da ora.ODSORPR.ODSORPR1.inst ONLINE ONLINE on iedm3303da ora.ODSORPR.ODSORPR2.inst ONLINE ONLINE on iedm3304da ora.ODSORPR.db ONLINE ONLINE on iedm3304da ora.ODSTTPR.ODSTTPR1.inst OFFLINE OFFLINE ora.ODSTTPR.ODSTTPR2.inst ONLINE ONLINE on iedm3304da ora.ODSTTPR.db ONLINE ONLINE on iedm3304da ora.iedm3303da.ASM1.asm ONLINE ONLINE on iedm3303da ora.iedm3303da.LISTENER_IEDM3303DA.lsnr ONLINE ONLINE on iedm3303da ora.iedm3303da.gsd ONLINE ONLINE on iedm3303da ora.iedm3303da.ons ONLINE ONLINE on iedm3303da ora.iedm3303da.vip ONLINE ONLINE on iedm3303da ora.iedm3304da.ASM2.asm ONLINE ONLINE on iedm3304da ora.iedm3304da.LISTENER_IEDM3304DA.lsnr ONLINE ONLINE on iedm3304da ora.iedm3304da.gsd ONLINE ONLINE on iedm3304da ora.iedm3304da.ons ONLINE ONLINE on iedm3304da ora.iedm3304da.vip ONLINE ONLINE oniedm3304da
svrctl commands to start up OFFLINE services
Instance ODSTTPR1 is down to restart:
srvctl start instance -d ODSTTPR -i ODSTTPR1
End of srvctl commands
######################## end of Output ####################
Notice in the output the OFFLINE record is read and the output to restart that instance is generated. I use this script for administration mainly for when I need to bring down one set of instances or something so I don't have to retype the startup commands. At the same time as checking status I can get the commands to start it up. It has been helpful at certain early morning workouts.
Feel free to comment and to modify this is just a quick and dirty base. Received on Wed Nov 16 2005 - 14:42:12 CST