Time Calculation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Time Calculation
# 1  
Old 02-03-2009
Time Calculation

I have a file with over 100,000 lines of data with looking to compare times of about 2000 lines to get a total time of a process. The lines of unique data are as follows.

Code:
FINER: CacSoapServer:reserveNetworkResource got the sessionID

and
Code:
INFO: Created CAC session ID

The command that I use to collect the data is below.
Code:
 
egrep 'FINER: CacSoapServer:reserveNetworkResource got the sessionID|INFO: Created CAC session ID' cac.log.0

Below is a sample of the output
Code:
Feb 03 06:36:43.652 33 FINER: CacSoapServer:reserveNetworkResource got the sessionID [0000019c9d06017266a3]
Feb 03 06:36:43.701 33 INFO: Created CAC session ID 0000019c9d06017266a3 due to Seachange server request

So for the command grep command that returned---------
Code:
Feb 03 06:36:43.701 33 INFO: Created CAC session ID 0000019c9d06017266a3 due to Seachange server request

I would like subtract the the time from the other output
Code:
Feb 03 06:36:43.652 33 FINER: CacSoapServer:reserveNetworkResource got the sessionID [0000019c9d06017266a3]

which should give me a processing time of 00:00:00.049

for each session there are the two messages I search on. Each session has a unique ID in it. For the session above it is 0000019c9d06017266a3.

So if some how I can get a command that will find those unique session ID's and compare those to searchable strings and give me a time from start to end, that would be great.

I have attached more samples on session samples.txt

Thanks
Brian

Last edited by zaxxon; 02-03-2009 at 08:00 AM.. Reason: Added code tags to make it readable
# 2  
Old 02-03-2009
Does this help?
Code:
#!/usr/bin/perl -W

while($line=<>){
        next if $line=~/INFO/;
        my @data=split / /,$line;
        $data[$#data-1]=~s/[\[\]]//;
        @time1=split /:/,$data[2];
        $line2=<>;
        @data=split / /,$line2;
        @time2=split /:/,$data[2];
        $time2[0]-=$time1[0];
        $time2[1]-=$time1[1];
        $time2[2]-=$time1[2];
        $time2[0]-=1 if $time2[1]<0;
        $time2[1]-=1 if $time2[2]<0;
        $time2[2]+=1 if $time2[2]<0;
        @data=split / /,$line;
        $data[2]=sprintf "%02d:%02d:%02.3f",$time2[0],$time2[1],$time2[2];
        print "@data";
}

# 3  
Old 02-03-2009
Pludi,

I am not too familiar with perl. In your post you have alot of data, time fields. My files on my box are CAC.LOG.0 and CAC.LOG.1. What do I need to fill in for it to work with my data.
Thanks
Brian
# 4  
Old 02-03-2009
Save the above code as a script (eg. timediff.pl) and call it as
Code:
$ perl timediff.pl CAC.LOG.0

if CAC.LOG.0 has the same format as your example file.
If not, pipe the output of your egrep into the script, eg
Code:
$ <long egrep line> | perl timediff.pl

If you make the script executable, you can omit calling perl in the command line and just use ./timediff.pl
# 5  
Old 02-03-2009
Pludi,

Seems to work great!!!

Thank You
# 6  
Old 02-03-2009
Pludi,

I tried it again, it appears it is messing up on


cac.log.1:Feb 03 00:00:0.077 19 FINER: CacSoapServer:reserveNetworkResource got the sessionID [0000019cfdcc01db961f]
cac.log.1:Feb 03 00:00:0.072 16 FINER: CacSoapServer:reserveNetworkResource got the sessionID [000001c1ba5a01dba43f]
cac.log.1:Feb 03 -9:-32:-44.930 16 FINER: CacSoapServer:reserveNetworkResource got the sessionID [000041e390bb01dbb6f5]

$ grep -c Create cac_session
746
$ grep 000041e390bb01dbb6f5 cac_session
cac.log.0:Feb 03 08:31:46.002 16 INFO: Created CAC session ID 000041e390bb01dbb6f5 due to Seachange server request
cac.log.1:Feb 03 08:31:45.930 16 FINER: CacSoapServer:reserveNetworkResource got the sessionID [000041e390bb01dbb6f5]

It looks like at that time, it changed seconds. Not sure if that's why, but it stopped the script
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Time calculation

Hi Gurus, I need to get one hour before time is yyyymmddhh format. ex. date +"%Y%m%d%H" gives 2017052814 but I need 2017052813 Thankx Please use CODE tags as required by forum rules! (6 Replies)
Discussion started by: nalakaatslt
6 Replies

2. Red Hat

Data transfer Time calculation

1 TB of data needs to read through 4 I/O channesl, each channels supports - 100 MB/s, What is average time taken to read the data ? Please give the formula for my understanding (2 Replies)
Discussion started by: Srini.rk1983
2 Replies

3. Shell Programming and Scripting

time calculation in ksh script

I"m trying to calculate the duration of of backup within a ksh shell script but I get an error. #!/bin/ksh STTIM=`date '+%T'` EDTIM=`date '+%T'` .... .... echo "DURATION OF BACKUP: $((EDTIM - STTIM))" (5 Replies)
Discussion started by: Bperl1967
5 Replies

4. Shell Programming and Scripting

Date time calculation

hello guys, I had been to many forums and many topics in this site as well for my question but did not get any solution. My question is how i can get y'day date with time stamp today is 20100729103819 and i am looking for output as 20100728103819. in simple words as we do in oracle sysdate-1... (4 Replies)
Discussion started by: lokaish23
4 Replies

5. Shell Programming and Scripting

Ksh Solaris Time calculation problem..Please help

I've gone through bunch of threads on time calculations but none of them helps on my problem I've to get the time difference in HHMM format from following inputs Input 1 : 01/08/2010 01:30 01/08/2010 03:20 Input 2 : 01/06/2010 22:00 01/07/2010 16:00 First input is easy but... (8 Replies)
Discussion started by: prash184u
8 Replies

6. Shell Programming and Scripting

Time stamp calculation

Hi all; I'm relatively new to scripting,I am working on a monitoring script.....where in i have to write subroutine which does the follows: It will check the time stamp of a file ( Oracle remarchive files) and compare it with existing time.If the time difference happen to be more than 90... (6 Replies)
Discussion started by: maverick_here
6 Replies

7. Shell Programming and Scripting

Time difference calculation

Hi Team, I am currently in the process of writing a script which will take a filename in the format SKADEV.0.db2.NODE0000.CATN0000.20080714231015.001 where the sixth string(with "." as the seperator) is the time stamp of the time of creation of the file. now here is my issue . I need to be... (2 Replies)
Discussion started by: Segwar
2 Replies

8. UNIX for Dummies Questions & Answers

Average completion time calculation?

I've been trying all night to come up with a script that will take a file that contains job completion times like this as input: 18:30 17:45 16:39 18:01 17:50 ... and figure the Average completion time. I've tried several things, and I just can't seem to get it to figure correctly. I'm... (5 Replies)
Discussion started by: Seawall
5 Replies

9. Shell Programming and Scripting

script execution time calculation

I am writting a script in the ksh shell and am trying to find a way to report the total execution time of the script without requiring the user to specify the time function when executing the script. Does anyone have any examples they have used. I have been setting up two date variables (one at... (9 Replies)
Discussion started by: johnsonbryce
9 Replies

10. UNIX for Advanced & Expert Users

time calculation

Hi, I have start time as a string like 06:04:01 and end time like 06:05:01 i need do a simple math to get the duration. What is the best way to do this in Korn Shell scripting? Thanks (2 Replies)
Discussion started by: liux99
2 Replies
Login or Register to Ask a Question