Logs between two time stamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logs between two time stamp
# 1  
Old 11-06-2015
Logs between two time stamp

I am creating log monitoring script and stuck up to get the logs between two time stamp.

can you please help me to create the script to get the logs between two time stamp, for example, I need the complete logs between
Code:
 # Time: 150328  1:30:10 and # Time: 150328 19:10:57

OS : Cent OS 6.x
Date format in the log :
Code:
 `date "+%y%m%d  %H:%M:%S"`

Sample logs:
Code:
# Time: 150328  1:30:10
# User@Host: testuser[testuser] @ test.domain.com [192.168.1.1]
# Query_time: 20.00009 Lock_time: 0.000063 Rows_sent: 9  Raw_del: 1
SET timestamp=1234567890;
xyz-set order number =  xxxx. phone number = null, phone number = test, email_ address=null street address place=null direction=gps test=query email address=invalidate
code=testzero first email from test user zip = 0000 house number = 0000 zip_house location level_of_service error invalid test_test123 floor=null room=null status_code
buillding_address floor-bull where id 000 test 123:
# Time: 150328 11:15:15
# User@Host: testuser[testuser] @ test.domain.com [192.168.1.1]
# Query_time: 20.00009 Lock_time: 0.000063 Rows_sent: 9  Raw_del: 1
SET timestamp=1234567890;
xyz-set order number =  xxxx. phone number = null, phone number = test, email_ address=null street address place=null direction=gps test=query email address=invalidate
code=testzero first email from test user zip = 0000 house number = 0000 zip_house location level_of_service error invalid test_test123 floor=null room=null status_code
buillding_address floor-bull where id 000 test 123:
# Time: 150328 19:10:57

# 2  
Old 11-06-2015
Please, try:

Code:
perl -nle 'print if /150328\s+1:30:10/../150328\s+19:10:57/' zenkarthi.file

# 3  
Old 11-06-2015
it is printing all the logs. Also, the idea to run the script for every 20 mins and collect the past 15 mins logs....
# 4  
Old 11-06-2015
Given your sample is representative, i.e. the last line has a time stamp entry, and you can have a file somewhere holding the last time stamp, try
Code:
awk 'FNR==NR {START=$0; next} END {print > "lasttime"} $0 ~ START, EOF ' lasttime logfile

This User Gave Thanks to RudiC For This Post:
# 5  
Old 11-07-2015
Thanks RudiC. can you explain little more on this please?

As I mentioned, the script has to run every 20 mins to collect the past 15 mins logs from the log file...for example, if script is running at 8:00, it has to collect the logs from 7:45 to 8:00 if the log file has some update on that time...
# 6  
Old 11-07-2015
The last line, presumedly holding a time stamp, is stored in a separate file called "lasttime". At the next run, this time stamp is read, and the log file is parsed for it to start printing until end-of-file. For simplicity, it's always starting with that line; it doesn't subtract five minutes from a 20 min intervall. Aside, it would be difficult to match a time stamp that is exactly 15 min ago...
# 7  
Old 11-08-2015
oh Sorry, the last line is not holding the time stamp, by mistake I copied next line starting word, it has the time stamp...is any other way I can try instead of adding grep line in the script.

Code:
awk 'FNR==NR {START=$0; next} $0 ~ START, EOF ' lasttime log
grep -i "# Time:" log | tail -1  > lasttime

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference between time stamp

Hi All i have a file data like below format A, B 2016-04-14 16:30:00,2016-04-14 16:31:17 2016-04-14 16:40:00,2016-04-14 16:41:10 2016-04-14 16:50:00,2016-04-14 16:50:41 2016-04-14 17:00:00,2016-04-14 17:00:35 2016-04-14 17:10:00,2016-04-14 17:11:48 2016-04-14 17:20:00,2016-04-14 17:20:37 i... (2 Replies)
Discussion started by: Tarak_nath
2 Replies

2. Shell Programming and Scripting

How to collect the logs with in two time stamp ?

Hi Gurus I need to collect the logs between two time stamp... The log files 12 hours format (ex- Nov 14, 2013 12:10:16 AM UTC) I tried the below commands but no luck. awk '$0 >= "Nov 14, 2013 9:40:01" && $0 <= "Nov 14, 2013 9:55:01"' file sed -n '/Nov 14, 2013 7:58:00 PM UTC/,/Nov 14, 2013... (5 Replies)
Discussion started by: zenkarthi
5 Replies

3. Shell Programming and Scripting

Time stamp Difference

I have a log file which wrote time stamp like this 2013-02-11 00:46:40.389037 2013-02-12 11:46:40.197045 can any one help me to get the time stamp difference of these two line in seconds. (4 Replies)
Discussion started by: netdbaind
4 Replies

4. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

7. UNIX for Dummies Questions & Answers

How to get the next time stamp in perl?

Hi, I have to find the next time stamp in perl. Here is the code. @time = loaltime(time); print "\n Present time: $time:$time:$time \n"; For example if the time is: "12:55:02" after some process the time becomes 1:00:00. How do i check when it becomes 00:00 i.e from "12:55:02... (0 Replies)
Discussion started by: vanitham
0 Replies

8. UNIX for Dummies Questions & Answers

Date/Time Stamp

Hi All, Wondering if there is have a date added at the end of a test string. I have a hypothetical text file day one: John Paul George When the file day one is output, I'd like it to read something like this: John 101406 Paul 101406 George 101406 Day two, when the same text file... (0 Replies)
Discussion started by: JimmyFlip
0 Replies

9. Shell Programming and Scripting

greping with time stamp

Hi all, I want to grep a file name with time stamp as 30 minutes how can i??. Ex I will getting outputs in a file every minutes I want to grep it by a time intervals of 30 and show it . Any help will be great ! Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

10. UNIX for Dummies Questions & Answers

How to MV without changing Time Stamp

Hi, I need to move the set of files, and it should be same time stamp as previous. How to do this? (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question