In sweet memories of my ever loving brother "kutty thambi " ARUN KUMAR

Useful Scripts

script available to view CRS resources in a format that is
easier to read. Just create a shell script with:
#--------------------------- Begin Shell 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:
#   - $ORA_CRS_HOME should be set in your environment
RSC_KEY=$1
QSTAT=-u
AWK=/usr/xpg4/bin/awk    # if not available use /usr/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;}'
#--------------------------- End Shell Script -------------------------------
Example output:
[root@rac1 bin]# ./crsstat
HA Resource                                   Target     State
-----------                                   ------     -----
ora.rac1.ASM1.asm                             ONLINE     ONLINE on rac1
ora.rac1.CDBS.lsnr                            ONLINE     ONLINE on rac1
ora.rac1.LISTENER_RAC_RAC1.lsnr               ONLINE     ONLINE on rac1
ora.rac1.gsd                                  ONLINE     ONLINE on rac1
ora.rac1.ons                                  ONLINE     ONLINE on rac1
ora.rac1.vip                                  ONLINE     ONLINE on rac1
ora.rac2.ASM2.asm                             ONLINE     ONLINE on rac2
ora.rac2.CLONE.lsnr                           ONLINE     ONLINE on rac2
ora.rac2.LISTENER_RAC_RAC2.lsnr               ONLINE     ONLINE on rac2
ora.rac2.gsd                                  ONLINE     ONLINE on rac2
ora.rac2.ons                                  ONLINE     ONLINE on rac2
ora.rac2.vip                                  ONLINE     ONLINE on rac2
ora.rock.db                                   ONLINE     ONLINE on rac2
ora.rock.rock1.inst                           ONLINE     ONLINE on rac1
ora.rock.rock2.inst                           ONLINE     ONLINE on rac2
Script to Display Time in TERMINAL
#!/bin/bash
# clock.sh

# the script is executed inside a while without conditions
while :                                                                                  
do
 # time and date are formatted to show HH:MM:SS YYYY-MM-DD
 cmd=`date +"%H:%M:%S %F"`
 
 # cursor's current position is saved through an escape sequence
 echo -n -e "\033[s"

 # Uncomment the next two lines to clean up the whole first line, although it causes a lot of blinking
 #tput cup 0 0    # positions on row 0 col 0 (left top corner)
 #tput el         # cleans from position to end of line

 # to place the clock on the appropriate column, subtract the length of 'HH:MM:SS YYYY-MM-DD', which is 19,
 # from the total number of columns
 C=$((`tput cols` - 19))
 tput cup 0 $C    # positions cursor at row 0 col $C

 # clock will be shown green inverted
 # setaf 2 = green, smso = inverted
 COLOR=`tput setaf 2; tput smso`

 # back to normal screen colors
 NORMAL=`tput sgr0`
 
 # print the time-date output on the above position
 echo -n $COLOR$cmd$NORMAL
 
 # restore the cursor to whatever was its previous position
 echo -n -e "\033[u"
 
 # script is executed every second
 sleep 1
done
free counters
 
Share/Bookmark