Operating System - HP-UX
1752687 Members
5517 Online
108789 Solutions
New Discussion

Re: some help needed for scripting

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

Re: some help needed for scripting

>I got output as: IN0800A      0.0 min

 

If you want the time in seconds:

printf "%-12s %.1f sec\n", $4, (stop_time - start_time[$4])

zxcv
Super Advisor

Re: some help needed for scripting

Hi Dennis ,

 

Thanks its working.

Now a final question ,

 

Suppose i have a file with below lines in it ;

 

*** Start of chkrerun at  Thu Jan 26 22:06:25 IST 2012

*** End   of chkrerun at  Thu Jan 26 22:06:25 IST 2012  - RC =  0
*** Start of  SY0007  at  Thu Jan 26 22:06:31 IST 2012
*** End   of  SY0007  at  Thu Jan 26 22:06:32 IST 2012  - RC =  0
*** Start of  SY3100  at  Thu Jan 26 22:06:44 IST 2012
*** End   of  SY3100  at  Thu Jan 26 22:06:44 IST 2012  - RC =  0
*** Start of  SP0100  at  Thu Jan 26 22:06:45 IST 2012
*** End   of  SP0100  at  Thu Jan 26 22:07:20 IST 2012  - RC =  0
*** Start of spms0122 at  Thu Jan 26 22:07:21 IST 2012

*** End   of spms0122 at  Thu Jan 26 22:07:52 IST 2012  - RC =  0
*** Start of  SY9507  at  Thu Jan 26 22:07:53 IST 2012
*** End   of  SY9507  at  Thu Jan 26 22:07:57 IST 2012  - RC =  0
*** Start of stopgateway at  Thu Jan 26 22:08:02 IST 2012

*** End   of stopgateway at  Thu Jan 26 22:08:02 IST 2012  - RC =  0
*** Start of shutbtm at  Thu Jan 26 22:08:03 IST 2012

*** End   of shutbtm at  Thu Jan 26 22:08:03 IST 2012  - RC =  0
*** Start of  SY9600  at  Thu Jan 26 22:08:04 IST 2012
*** End   of  SY9600  at  Thu Jan 26 22:08:04 IST 2012  - RC =  0
*** Start of  UTDEBUG1  at  Thu Jan 26 22:08:05 IST 2012
*** End   of  UTDEBUG1  at  Thu Jan 26 22:08:05 IST 2012  - RC =  0
*** Start of  SY0007  at  Thu Jan 26 22:08:13 IST 2012
*** End   of  SY0007  at  Thu Jan 26 22:08:14 IST 2012  - RC =  0
*** Start of  SY3300  at  Thu Jan 26 22:08:25 IST 2012
*** End   of  SY3300  at  Thu Jan 26 22:08:25 IST 2012  - RC =  0
*** Start of  SY0199  at  Thu Jan 26 22:08:40 IST 2012
*** End   of  SY0199  at  Thu Jan 26 22:08:40 IST 2012  - RC =  0
*** Start of  CI0251  at  Thu Jan 26 22:08:41 IST 2012
*** End   of  CI0251  at  Thu Jan 26 22:25:43 IST 2012  - RC =  0
*** Start of  IN0869  at  Thu Jan 26 22:25:44 IST 2012
*** End   of  IN0869  at  Thu Jan 26 22:25:44 IST 2012  - RC =  0
*** Start of  IN0800A  at  Thu Jan 26 22:25:45 IST 2012
*** Start of  IN0800B  at  Thu Jan 26 22:25:50 IST 2012
*** Start of  IN0800C  at  Thu Jan 26 22:25:55 IST 2012
*** Start of  IN0800D  at  Thu Jan 26 22:26:00 IST 2012
*** Start of  IN0800E  at  Thu Jan 26 22:26:06 IST 2012
*** Start of  IN0800F  at  Thu Jan 26 22:26:11 IST 2012
*** Start of  IN0800G  at  Thu Jan 26 22:26:16 IST 2012
*** Start of  IN0800H  at  Thu Jan 26 22:26:21 IST 2012
*** End   of  IN0800B  at  Thu Jan 26 23:00:02 IST 2012  - RC =  0
*** End   of  IN0800D  at  Thu Jan 26 23:01:41 IST 2012  - RC =  0
*** End   of  IN0800F  at  Thu Jan 26 23:02:22 IST 2012  - RC =  0
*** End   of  IN0800C  at  Thu Jan 26 23:02:51 IST 2012  - RC =  0
*** End   of  IN0800A  at  Thu Jan 26 23:05:47 IST 2012  - RC =  0
*** End   of  IN0800G  at  Thu Jan 26 23:10:13 IST 2012  - RC =  0
*** End   of  IN0800E  at  Thu Jan 26 23:21:37 IST 2012  - RC =  0
*** End   of  IN0800H  at  Thu Jan 26 23:56:23 IST 2012  - RC =  0
*** Start of  IN0806A  at  Thu Jan 26 23:56:25 IST 2012
*** End   of  IN0806A  at  Thu Jan 26 23:56:25 IST 2012  - RC =  0
*** Start of  IN0806B  at  Thu Jan 26 23:56:27 IST 2012
*** End   of  IN0806B  at  Thu Jan 26 23:56:27 IST 2012  - RC =  0
*** Start of  IN0806C  at  Thu Jan 26 23:56:29 IST 2012
*** End   of  IN0806C  at  Thu Jan 26 23:56:29 IST 2012  - RC =  0

 

From the above i want to grepall o/p  from job SY3100 and continue till end of file;

 

i.e  the o/p should be like ;

       job name  time

       SY3100   0

       SP0100   yy 

       spms0122 zz

and so on till end of line....

..................

....................

   IN0806C   tt

 

Dennis Handly
Acclaimed Contributor

Re: some help needed for scripting

>From the above I want to grepall output from job SY3100 and continue till end of file:

 

You could do something like this.  Where the awk variable job_start is the first that prints:

awk -v job_start="SY3100" '
# day of month, HH:MM:SS (24 hour clock)
function convert_to_secs(day, hhmmss) {
#   print day, hhmmss
   split(hhmmss, t_hhmmss, ":")
   return (((day - 1) * 24 + t_hhmmss[1]) * 60 + t_hhmmss[2]) * 60 +  t_hhmmss[3]
}
BEGIN {
   print "job name   time"
}
$2 == "Start" {
   if ($4 != job_start && job_start != "") next  # skipping
   job_start = ""  # now handle rest of the jobs
   yyyymmmddzz[$4] = $7 $11 $10  # check for unhandled date straddling
   start_time[$4] = convert_to_secs($8, $9)
   next
}
$2 == "End" {
   if ($4 != job_start && job_start != "") next  # skipping
   if (yyyymmmddzz[$4] == "") {
      print "Cannot find Start time for", $4
      next
   }
   stop_yyyymmmddzz = $7 $11 $10  # check for unhandled date straddling
   if (stop_yyyymmmddzz != yyyymmmddzz[$4]) {
      print "Start/stop for", $4", straddles complex date boundary",
            stop_yyyymmmddzz
   }
   stop_time = convert_to_secs($8, $9)
#   printf "%s: %d\n", $4, start_time[$4]
#   printf "%s: %d\n", $4, stop_time
   printf "%-12s %.1f sec\n", $4, (stop_time - start_time[$4])
   next
}' smartlog.20120117.txt

zxcv
Super Advisor

Re: some help needed for scripting

Hi Dennis ,

I got the o/p what i was looking for .

 

Can we sort this o/p as per time taken ?

 

Thanks very much for ur valuable time and efforts  for this solution.

Dennis Handly
Acclaimed Contributor
Solution

Re: some help needed for scripting

>Can we sort this o/p as per time taken?

 

Yes, just pass the output to sort.  Unfortunately the title probably won't sort well and you may have to remove it from awk and add it back after the sort.  You may be in luck since the title sorts first:

awk ....

}' smartlog.20120117.txt | sort -n -k2,2  # sort on key 2, using numeric compares

 

zxcv
Super Advisor

Re: some help needed for scripting

Hi Dennis ,

 

Thank you very much for the solution.