1

I'm trying to parse apache log and print log entires generated in last n number of minutes

Sample of my access log data is here and this is what I have tried so far:

update The following solution works

awk -vDate=$(date -d'now-10 minutes' +[%d/%b/%Y:%H:%M:%S) '$4 > Date {print Date, $0}' access.log 
Deano
  • 11,582
  • 18
  • 69
  • 119
  • This approach isn't going to work well. The day isn't going to change in the last hour except right after midnight so you need a date format that includes the minutes. That's easy, the problem is that won't necessarily match any line in your input so you can't use a range like that. Use something else for this. Like `awk` or an actual tool designed to parse/handle apache logs (there are many of them). – Etan Reisner Apr 06 '16 at 17:01
  • Can you suggest any tool that I might be able to use to do that? I'm more interested in getting access data by time. – Deano Apr 06 '16 at 17:04
  • 1
    Try `awk -vDate=$(date -d'now-10 minutes' +[%d/%b/%Y:%H:%M:%S) '$4 > Date {print Date, $0}' access.log` from [there](http://stackoverflow.com/a/7714878/3776858). – Cyrus Apr 06 '16 at 17:24
  • 1
    That seems to work! Thank you – Deano Apr 06 '16 at 17:32
  • Yes, it is a duplicate. – Cyrus Apr 06 '16 at 18:15

0 Answers0