Find logs between two timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find logs between two timestamp
# 1  
Old 07-19-2012
Find logs between two timestamp

Suppose there are log entries like

16 Jul 2012 11:46:45,628 [ERROR] SendToClientService [ACTIVE] ExecuteThread: '256' for queue: 'weblogic.kernel.Default (self-tuning)': Received an unknown fault.

16 Jul 2012 11:47:45,650 [ERROR] SendToClientService [ACTIVE] ExecuteThread: '256' for queue: 'weblogic.kernel.Default (self-tuning)': CL1ESB0030S9010 [1] Error while Checking file Formats.

How to search these entries between two given timestamp?

Thanks in Advance.
# 2  
Old 07-19-2012
Code:
sed -n '/16 Jul 2012 11:46:45,628/,/16 Jul 2012 11:47:45,650/p' file

# 3  
Old 07-19-2012
I have tried this in below logs,

13 Jul 2012 12:00:18,566 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming Incoming file

13 Jul 2012 12:00:28,181 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming Incoming file

13 Jul 2012 12:00:30,943 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming Incoming file:

13 Jul 2012 12:00:43,423 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming file

I gave there

sed -n '/13 Jul 2012 12:00:28,000/,/13 Jul 2012 12:00:45,650/p' file

it shows nothing. By this command its only mactthing pattern, but I need something which can search the from the starting time stamp which may not be present in the log, and same in the case of ending time stamp. so, we need to search entries between 13 Jul 2012 12:00:28,000 and 13 Jul 2012 12:00:45,650, it will display


13 Jul 2012 12:00:28,181 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming Incoming file

13 Jul 2012 12:00:30,943 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming Incoming file:

13 Jul 2012 12:00:43,423 [INFO ] SendToClientService [ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)': Incoming file
# 4  
Old 07-19-2012
Hi

here is a fast and ugly but working solution in perl

Code:
 perl -ne 'BEGIN {$a="13 Jul 2012 12:00:28,000"; $b="13 Jul 2012 12:00:45,650"; $a=`date -d "$a" +%s`; $b=`date -d "$b" +%s`;} $r=`date -d "$1" +%s` if /^(.*?)\[/; print if ($r <= $b) && ($r >= $a);' file

# 5  
Old 07-23-2012
Approximate String Matching:
Code:
sed -n '/13 Jul 2012 12:00:28/,/13 Jul 2012 12:00:45/p' file


Last edited by Franklin52; 07-24-2012 at 08:36 AM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find files and sort by timestamp

Used below command to get list of files sorted by timestamp find -L . -type f -name '*dat*' | xargs ls -ltrg I want to get only the filenames so I tried adding basename but it doenst work , can some one advise on how to get only file name (1 Reply)
Discussion started by: lalitpct
1 Replies

2. Shell Programming and Scripting

Need logs between timestamp

Hi, I need to count the number of lines wc command for next 12 hrs in the log file given the starting time in the log (hello.log) looks like the below. 135.63.34.29 - - "POST /ShopCart/MyBest HTTP/1.1" 200 6310 130.15.126.22 - - "POST /ShopCart/MyBest HTTP/1.1" 200 4021 130.18.16.2 - - ... (2 Replies)
Discussion started by: ashare.ahmed
2 Replies

3. UNIX for Dummies Questions & Answers

How to Find zipped logs?

from time to time, I received an alert, let's call it "alert_name"but in order to run the script that loads the missing data, I need to check firs if the logs have been zipped out, how can I do this? I Know: 1.- Name of the alert. 2.- Server where it runs. (4 Replies)
Discussion started by: JLo5621
4 Replies

4. Shell Programming and Scripting

How to append timestamp in the filenames using find?

Hi, How to change the filenames with timestamp in sub folders I have the following code to select the records. find . -type f -name '*pqr*' -ctime 1 -print The following is the example app_root_dir="/`echo $ScriptDir | cut -d'/' -f2`" $app_root_dir/../BadFiles directory uvw.bad... (3 Replies)
Discussion started by: bobbygsk
3 Replies

5. UNIX for Dummies Questions & Answers

Find last executed timestamp

Hi, on our hp-ux box we have 100s of shell scripts in a bin folder. Now i have to figure out which scripts are not being used at all. The timestamp for these are the ones when they were promoted to this 'bin' folder. Now, how can I find when was the last time each of these scripts were run? I... (2 Replies)
Discussion started by: ysrini
2 Replies

6. Shell Programming and Scripting

To find latest set of logs among new and old

Hi All I am writing a script which will select the latest logs (which are generated every night via a script) among old one and new. Script generates set of 3 logs each time it runs. Example : log-WedJun082011_bkt1.log log-WedJun082011_bkt2.log log-WedJun082011_bkt3.log I have... (1 Reply)
Discussion started by: ratneshnagori
1 Replies

7. Shell Programming and Scripting

To find out the logs count

Hi, I am using the below command to find out the mail logs which will grep the repeated message ids: less /var/log/messages |awk '{print +$6}'| sort | uniq -c | sort -nr OUTPUT: 506 1246382279 404 1246373467 303 1246383457 303 1246382268 300 1246379705 202... (7 Replies)
Discussion started by: gsiva
7 Replies

8. Shell Programming and Scripting

how to grep the logs for two particular timestamp

Hi, could anyone help me out how to write a script, to grep the two timestamp from a particular file, so that it will list out all the logs between the particular timestamp I have a pattern of log: servicename operationname starttime endtime eg., servicename1 operationname1 01:11:11... (1 Reply)
Discussion started by: jacktolearn
1 Replies

9. UNIX for Dummies Questions & Answers

find logs

hi friends, how do i modify the "find" command to search for large files with *.log extension along with a mtime parameter for files that are 30days, 1yr, 2yr old . please help my dear friends, thanks in advance (2 Replies)
Discussion started by: cromohawk
2 Replies

10. Shell Programming and Scripting

Find a value and the previous timestamp

Hi, I need to do a script that find a specific data in var_5 and also the previous timestamp. This is the file I have: var_1=data1 var_2=data2 var_3=data3 var_4=data4 var_5=data5 var_6=data6 var_7=data7 RESULT PRINTOUTS: 6404 var_1=data8 var_2=data9 var_3=data10 var_4=data11... (7 Replies)
Discussion started by: gcsilva
7 Replies
Login or Register to Ask a Question