Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP CALCULATING THE TIME A JOB RUNS (TIME2 - TIME1)

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
0
0
US
I am attempting to calculate the run time for each job in a log file (mutiple jobs are written to one log file), however I am unsure of how to go about doing such. Below is an example of some lines from the log file:

Job Begin Date Begin T End Date End T Status
job1 01/02/2003 00:30 01/02/2003 00:30 Successful
job2 01/02/2003 00:35 01/02/2003 00:40 Successful

I would assume something like the awk command below would work, however it does not, most likely due to the fact that they are not ordinary numbers.

nawk '$1 ~ /string/ {run_time= $5 - $3; print run_time}' filename

Any help would be greatly appreciated.

Thanks,

John
 
look: man time -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
John:

I'm making the assumption your begin and end times are hours:minutes. The awk split command splits $3 and $5 into an array where the first element is hours and the second is minutes. Change the two elements to minutes and perform a subtraction.

If my assumption is wrong, it should be a simple matter to fix it.

Happy New Year.

Ed

# no error checking other than skipping the heading
awk ' {
if(NR == 1) # Line 1 is the heading
{
print $0
continue
}

split($3, arg3, ":")
nos3=((arg3[1] * 60) + arg3[2])

split($5, arg5, ":")
nos5=((arg5[1] * 60) + arg5[2])

# diff in miniutes
print nos5-nos3

} ' f.file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top