LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Want to get last 24 hours data from a log file (https://www.linuxquestions.org/questions/linux-newbie-8/want-to-get-last-24-hours-data-from-a-log-file-938243/)

vaw 04-05-2012 04:19 AM

Want to get last 24 hours data from a log file
 
Hi,

I have a log file, which has data similar to :

[2011-11-11 00:33:53,962] xyz
[2011-11-21 01:28:01,269] abc
[2011-11-30 00:52:56,444] bcd

I want to be able to pull out data that is less than 24 hurs old from this file, so that on a daily basis i can get a report having data of last 24 hours.

Could you please let me know, using unix, how can i filter the data that i need ?

TB0ne 04-05-2012 09:37 AM

Quote:

Originally Posted by vaw (Post 4645260)
Hi,
I have a log file, which has data similar to :

[2011-11-11 00:33:53,962] xyz
[2011-11-21 01:28:01,269] abc
[2011-11-30 00:52:56,444] bcd

I want to be able to pull out data that is less than 24 hurs old from this file, so that on a daily basis i can get a report having data of last 24 hours.
Could you please let me know, using unix, how can i filter the data that i need ?

Similar question to your other thread, where someone even wrote you a script to do something similar. Have you tried to modify that? You can also just use grep to look for whatever string you want, and save those results into another file.

You can also use logrotate, and have it set to archive log files every day, so that your logs will only EVER have 24 hours of data in them, going back as far as you'd like. Read the man pages on grep and logrotate.


All times are GMT -5. The time now is 05:54 AM.