Quick script for searching patch timings from command line..

Preface


Sometimes you may have to find the timings of a particular patch quickly. Can we write a quick script to find the timings on different tiers (admin tier, web tier, forms tier etc)? Would it not be advantageous to have such a script.

If you take the idea further, you can even setup SSH keys across the diffrent tiers and execute this script remotely. Imagine the productivity you can achieve sitting remotely, especially when you may been asked to come up with the patch application timings for a bunch of 20 patches across all the tiers of a test instance.

In such a scenario, simple SSH key setup and a handy unix script would be wonderful. In this example, I give you the ability to extend such a script, which is built on really simple logic of pattern searching. It would be a good case study for people learning shell scripting.

Example of the find patch timing script

midserver1.corp.company.us:web_qa> ./find_time_taken_for_a_patch.sh 6133653
Filename: 6133653_NLS_u_merged.log
------------------------------
Started:  Fri Aug 31 2007 08:27:48
Ended:   Fri Aug 31 2007 08:33:56
Time Taken: elapsed: 0:6:8 (368 seconds)
Filename: u6133653.log
------------------------------
Started:  Fri Aug 31 2007 08:11:40
Ended:   Fri Aug 31 2007 08:20:22
Time Taken: elapsed: 0:8:42 (522 seconds)

The script assumes an auxiliary script called timediff.sh and two other awk scripts for finding the last start and end time of adpatch session. It assumes that the patching logs are in $APPL_TOP/admin/$TWO_TASK/log.

At this point, it doesnt not check if basic environment variables like $APPL_TOP and $TWO_TASK are set, but that is easily done. It would make for good homework for the reader.

Using this concept at the next Level

To do batch processing and save effort, this can be taken to the next level by writing a small wrapper for a bunch of patches (say).

midserver1.corp.company.us:web_qa> more patches
6242856
6339534
5161680

5989593

5474883

5473858

5382500

5337777

midserver1.corp.company.us:web_qa> for patch in `cat patches`
do
  #

  # Assuming that SSH key has been setup between
  # myserver1 and myserver2
  #
  ssh myserver2 ". setdb QA;  
                 $HOME/find_time_taken_for_a_patch.sh $patch"

  
$HOME/find_time_taken_for_a_patch.sh $patch
done

Listing of the shell/awk scripts

find_time_taken_for_a_patch.sh

midserver1.corp.company.us:web_qa> more find_time_taken_for_a_patch.sh
#!/bin/ksh

[ $# -lt 1 ] && echo "Usage: `basename $0` <patch#>" && exit 1

patch=$1
cd $APPL_TOP/admin/$TWO_TASK/log

for i in *${patch}*.log
do
start_time=`awk -f $HOME/find_start_time.awk $i`
end_time=`awk -f $HOME/find_end_time.awk $i`
echo "Filename: $i\n------------------------------"
echo "Started: $start_time"
echo "Ended: $end_time"
stime=`echo $start_time | awk '{ print $NF}'`
etime=`echo $end_time | awk '{ print $NF}'`
echo "Time Taken: `$HOME/timediff.sh $stime $etime`"
done

timediff.sh



#!/bin/ksh

( [ -z $1 ] || [ -z $2 ] ) && exit 1

time=$1
h1=$(expr "$time" : "\(..\):..:..")
m1=$(expr "$time" : "..:\(..\):..")
s1=$(expr "$time" : "..:..:\(..\)")

time=$2
h2=$(expr "$time" : "\(..\):..:..")
m2=$(expr "$time" : "..:\(..\):..")
s2=$(expr "$time" : "..:..:\(..\)")

#echo "from=$h1:$m1:$s1 to=$h2:$m2:$s2"

seconds=$(echo "$h2*3600+$m2*60+$s2-($h1*3600+$m1*60+$s1)" | bc)

if [ "$seconds" -lt 0 ] ; then
((seconds=seconds+86400))
fi

hh=$(expr $seconds / 3600)
mm="$(expr \( $seconds - $hh \* 3600 \) / 60)"
ss="$(expr $seconds - $hh \* 3600 - $mm \* 60)"
echo "elapsed: $hh:$mm:$ss ($seconds seconds)"

find_start_time.awk

################################################################
# this is the input pattern which will be used for finding the
# start time
################################################################
#  Start of AutoPatch session
# AutoPatch version: 11.5.0
# AutoPatch started at: Fri Aug 31 2007 07:21:10
################################################################
/Start of AutoPatch session/ { started=""; getline; getline; for (i=4;i<=NF;i++) started=started" "$i; };
END { print started }

find_end_time.awk



# Log and Info File sync point:
# Fri Aug 31 2007 07:50:38
# AutoPatch is exiting successfully.

/Log and Info File sync point:/ { getline; ended_time=$0; getline; if ($0 !~ /AutoPatch is exiting successfully/) ended_ti
me=""; }
END { print ended_time }


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

bocadmin_ww

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today