Sponsored Content
Top Forums Shell Programming and Scripting time diffrence between two lines in a log file Post 302311327 by ghostdog74 on Tuesday 28th of April 2009 11:38:11 AM
Old 04-28-2009
you can't just expr and subtract time/date like that. you might want to use some date manipulation module, like that of Date::Calc/strptime/strftime that goes with Perl. here's one way with Python
Code:
import time

def calctime(line):
    line = line.split()
    day,month,mday, TIME, year = line[0],line[1],line[2],line[3],line[4]    
    hr,mm,sec = TIME.split(":")
    sec,ms = sec.split(".")
    time2parse = "%s %s %s %s:%s:%s %s" % (day,month,mday,hr,mm,sec, year)
    stringtime = time.strptime(time2parse,"%a %b %d %H:%M:%S %Y")
    return [time.strftime("%s",stringtime),ms]

for line in open("file"):
    flag=1
    line=line.strip()
    if "Entering ARRF_LIB_Evaluate" in line:
        startT,startms = calctime(line)        
    if "Exiting ARRF_LIB_Evaluate" in line:
        endT,endms = calctime(line)        
        flag=0
    if flag == 0:
        diff = int(endT) - int(startT)
        if diff==0: print "Time difference(ms) " , int(endms) - int(startms)
        else: print "Time different %d (s)" % diff

output
Code:
# ./test.py
Time difference(ms)  78

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Can any how we can find the time diffrence...?

Hi, I am trying to caluate the time elasped by the job to run.For that i have used the following command: I have one file which contains the following more start.txt 991 STARTED Fri Aug 10 14:04:20 2007 Starting Job JOB_NAME. (...) 1036 STARTED Fri Aug 10 14:04:31 2007 ... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

2. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

3. Shell Programming and Scripting

To find the time difference between two lines of the same log file

Hello Friends, I want to write a script for the following: nlscux62:tibprod> grep "2008 Apr 30 01:" SA_EHV_SPEED_SFC_IN_03-SA_EHV_SPEED_SFC_IN_03-2.log | grep -i post | more 2008 Apr 30 01:01:23:928 GMT +2 SAPAdapter.SA_EHV_SPEED_SFC_IN_03-SA_EHV_SPEED_SFC_IN_03-2 Info AER3-000095 IDOC... (2 Replies)
Discussion started by: satyakam
2 Replies

4. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

5. Shell Programming and Scripting

Get all lines in a file after particular time

Hi All, I am lookig for a way to get all the lines from a log file which has been updated 5 mins prior to the system time. The log file will be like below: 09:01:00 Started polling 09:01:05 Checking directory test 09:02:00 Error! Cannot access directory test 09:03:00 Polling I get... (8 Replies)
Discussion started by: deepakgang
8 Replies

6. Shell Programming and Scripting

Find time difference between two consecutive lines in same file.

Hello I have a file in following format: IV 08:09:07 NM 08:12:01 IC 08:12:00 MN 08:14:20 NM 08:14:15 I need a script to compare time on each line with previous line and show the inconsecutive line. Ex.: 08:12:00 08:14:15 A better way... (6 Replies)
Discussion started by: vilibit
6 Replies

7. Shell Programming and Scripting

Read two lines at time from a file

Hello community, what I need to do is read 2 rows at time from a file. I have this simple solution: File to read: LINE1 LINE2 LINE3 LINE4 LINE5 LINE6 LINE7 LINE8Read routine:#!/bin/ksh sed '1,3d' /out.txt | while read line; do read line2 echo $line $line2 doneResult:LINE1... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

8. Shell Programming and Scripting

Read multiple lines at a time from file

Hello All, I have a file like below.... dn: cn=user1,ou=org,o=org cn=user1 uid=user1 cn=user2,ou=org,o=org cn=user2 uid=user2 cn=user3,ou=org,o=org cn=user3 cn=user33 uid=user3 cn=user4,ou=org,o=org cn=user4 uid=user4 (6 Replies)
Discussion started by: s_linux
6 Replies

9. Shell Programming and Scripting

Check/Parse log file's lines using time difference/timestamp

I was looking at this script which outputs the two lines which differs less than one sec. #!/usr/bin/perl -w use strict; use warnings; use Time::Local; use constant SEC_MILIC => 1000; my $file='infile'; ## Open for reading argument file. open my $fh, "<", $file or die "Cannot... (1 Reply)
Discussion started by: cele_82
1 Replies

10. Shell Programming and Scripting

Collecting all lines between two time stamp from the log

Can you help me to collect the entire logs between two time stamp. The below awk command collecting the logs only if the line has time stamp. awk '$0>=from && $0<=to' from="150318 23:19:04" to="150318 23:55:04" log file 150318 23:19:04 logentries 150318 23:29:04 logentries 150318... (11 Replies)
Discussion started by: zenkarthi
11 Replies
ATSADC(1)							       local								 ATSADC(1)

NAME
atsadc, atsa1, atsaftp, atsahttp -- counter-collection SYNOPSIS
atsadc [ t n ] [ ofile ] atsa1 [ t n ] atsaftp atsahttp DESCRIPTION
System activity-data can be gathered on special request of a user [see atsar(1) ] or automatically, on a routine basis, as described here. Usually the kernel maintains statistical counters that are incremented as various system actions occur. These include counters for CPU uti- lization, disk utilization, memory utilization and various network statistics. The program atsadc and the shell-script atsa1 are used to collect, save, and process these counters. The program atsadc (the data collector) samples system data n times with an interval of t seconds between samples, and writes in binary format to ofile or (default) to standard output. The sampling interval t should be greater than 1 second. If t and n are omitted, a special reset-record is written. This facility is used when booting to a multi-user state, to mark the time at which the counters restart from zero. For example, the reset-mark can be added to the daily data by the command: /usr/local/bin/atsadc /var/log/atsar/atsa`date +%d` Note that this entry is written to the /etc/rc.d/init.d/atsar file. The shell-script atsa1 is used to collect and store data in the binary file /var/log/atsar/atsadd where dd is the current day of the month. The arguments t and n cause records to be written n times at an interval of t seconds, or once if omitted. Furthermore this script takes care that log-files older than a week are removed once a day. A file containing following entries should be added to the /etc/cron.d directory to produce records every 20 minutes during working hours and hourly otherwise: 0 * * * 0-6 root /usr/local/bin/atsa1 20,40 8-17 * * 1-5 root /usr/local/bin/atsa1 See crontab(1) for details. The shell-script atsaftp counts the new transfers registered in the FTP-logfile(s) since the previous time this script was activated; the new counters are stored in the /var/log/atsar/ftpstat file in ASCII-format. The names of the FTP-logfiles to be watched are specified in the /etc/atsar.conf configuration-file. The shell-script atsahttp counts the new transfers registered in the HTTP-logfile(s) since the previous time this script was activated; the new counters are stored in the /var/log/atsar/httpstat file in ASCII-format. The names of the HTTP-logfiles to be watched are specified in the /etc/atsar.conf configuration-file. Both scripts must be activated just before the program atsadc is started, which also collects these counters. FILES
/var/log/atsar/atsadd Daily data file, where dd are digits representing the day of the month. SEE ALSO
atsar(1), crontab(1) AUTHOR
Gerlof Langeveld, AT Computing (gerlof@ATComputing.nl) AT Computing July 2004 ATSADC(1)
All times are GMT -4. The time now is 05:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy