Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log between two Time

 
nazzy khan
Ranch Hand
Posts: 39
Android Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How do I grep log between two times.

Say, I want logs between 18 Feb 2011 12:40 and 18 Feb 2011 22:28

I have tried this by egrep, sed and awk but could not get the right logs.


awk '/18\/Feb\/2011:12:40:/, /18\/Feb\/2011:22:28:/' app_server.log | grep -i "error"

It gives me error says... awk: record `2011-02-18 00:00:15,...' too long



Any idea how to get logs between two timestamp...

Thanks

-nazzy
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grep doesn't parse timestamps, and neither will your AWK script. You're going to need something more intelligent.

Some Linux distros came with a log viewer app that might be able to help, but I don't know what's available at the moment. I think the viewer may have been named something like "sawmill".

Failing that, you could write a perl or python script that parsed the dates and filtered lines. Or, for that matter, a Java Application using the DateParser class. Probably doable in about 100 lines of Java.

AWK might be able to handle the date parsing, too, but it would be a lot of work, I think.
 
nazzy khan
Ranch Hand
Posts: 39
Android Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim for giving some suggestions...

I'll look into that and will let you know


-nazzy
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I didn't get the question right, but this works for me:

Yes, you have to know in advance whether those timestamps are present in the logfile, because the patterns aren't regarded as date/time, but simply as strings. Filter from this to that string.


 
Krzysztof Otrebski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using OtrosLogViewer with timefilter. This is a Swing desktop application, but it can open files from SSH/SFTP servers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic