Results 1 to 2 of 2
Hello,
the log lines start with date and time like this:
Jun 16 08:37:18 166.59.86.116 /opt/....
Jun 16 08:38:19 166.59.86.116 /opt/...
Jun 16 08:38:19 166.59.86.116 /opt/...
Jun 16 08:40:19 166.59.86.116 ...
- 06-16-2009 #1Just Joined!
- Join Date
- Jun 2009
- Posts
- 1
grep from a log the lines generated in the last 4 minutes
Hello,
the log lines start with date and time like this:
Jun 16 08:37:18 166.59.86.116 /opt/....
Jun 16 08:38:19 166.59.86.116 /opt/...
Jun 16 08:38:19 166.59.86.116 /opt/...
Jun 16 08:40:19 166.59.86.116 /opt/...
I need to grep the lines with a certain error and that were generated in the last 4 minutes, e.g. if current time is Jun 16 08:43 I need the lines starting from Jun 16 08:38:19.
Is that possible with a bash script or perl code?
- 06-16-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
In bash you can determine what the time was 4 minutes ago with the command:
The thing to do is format the times so you can do string comparisons. Usually I format the date/time as: yyyymmddhhmmss (which is year, month, day, hour, minute, second). Look and the date manpage on how to format the date/time.Code:date --date="4 minutes ago"


Reply With Quote