I have a log file:
http://pastebin.com/raw.php?i=cdUpTqNV
the first column, before the "ASDF" is the same time, as in the given row, but in unix time [i think it's easier to do this with unix time].
I just need the lines what was in the last 2 minutes:
Ending: 07:55:08 - the last time in the logfile
Starting: 07:53:09 - at most 2 minutes before the last log line in the logfile
The output of the pastebined text would be:
1295938389ASDF 01 25 07:53:09 router authpriv.notice dropbear[20673]: password auth succeeded for 'root' from 192.168.1.201:43822
1295938401ASDF 01 25 07:53:21 router daemon.info dnsmasq-dhcp[1140]: DHCPREQUEST(br-lan) 192.168.1.201 01:2c:23:c3:32:f3
1295938401ASDF 01 25 07:53:21 router daemon.info dnsmasq-dhcp[1140]: DHCPACK(br-lan) 192.168.1.201 01:2c:23:c3:32:f3
1295938508ASDF 01 25 07:55:08 router daemon.info dnsmasq-dhcp[1140]: DHCPREQUEST(br-lan) 192.168.1.201 01:2c:23:c3:32:f3
1295938508ASDF 01 25 07:55:08 router daemon.info dnsmasq-dhcp[1140]: DHCPACK(br-lan) 192.168.1.201 01:2c:23:c3:32:f3
How to do this using only minimal *nix tools? [it's an OpenWrt router, no perl :( ]
so, how to do this: output only line(Last log line time - 120sec)?
Thank you!
Give this a try:
You can get current timestamp like this:
And current timestamp - 2mins for example this way:
So you have two integer values and you want to grep lines which starts within this range. There are many ways how to do it (awk, sed,...)
Sed example:
For other ways, try this magnificent tool: http://lmgtfy.com/?q=grep+number+range