[CentOS] Unable to grep 5 mins logs

Mon Jun 13 07:36:45 UTC 2011
ankush grover <ankushcentos at gmail.com>

Hi Friends!

I need to prepare a script which will grep logs from the current time
to previous 5 mins that is if the current time is Mon Jun 13 12:40:40
IST 2011 then all the logs between the interval Mon Jun 12:35 - 12:40
2011 should be grepped by the script and append it to another file.
However, the below script is not able to grep the desired logs, so I
need some help in preparing the script. I am running Centos 5.2
32-bit.



for (( i = 5; i >=0; i-- )) ; do grep $(date "+%a %b %d %R %Y" -d "-$i
 min") /var/ossec/logs/active-responses.log >> /tmp/newlog.log;done


/var/ossec/logs/active-responses.log format is below
Fri Jun  3 15:38:14 IST 2011
/var/ossec/active-response/bin/host-deny.sh add - 172.31.5.12
1307095694.71353 31151
Fri Jun  3 15:38:14 IST 2011
/var/ossec/active-response/bin/firewall-drop.sh add - 172.31.5.12
1307095694.71353 31151



Thanks & Regards


Ankush