Unix Scripts

Script to View CRS resource in a tabular format

#--------------------------- 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:  
#   - $ORACLE_HOME should be set in your environment  
RSC_KEY=$1  
QSTAT=-u  
AWK=/usr/bin/awk  
# Table header:echo ""  
$AWK \  
'BEGIN {printf "%-45s %-10s %-18s\n", "HA Resource", "Target", "State";  
   printf "%-45s %-10s %-18s\n", "-----------", "------", "-----";}'  
# Table body:  
$ORACLE_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 -------------------------------

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 "33[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 "33[u"  

 # script is executed every second  
sleep 1  
done
#--------------------------- End Shell Script -------------------------------
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Oracle database internals by Riyaj

Discussions about Oracle performance tuning, RAC, Oracle internal & E-business suite.

StartupForce

Where all the Action Is !!!!

Pavan DBA's Blog

The DBA Knowledge Store

ORACLE-BASE - Latest Articles

Where all the Action Is !!!!

%d bloggers like this: