Unix Shell - date question

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2006 > date question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author date question
morty3e@gmail.com

2006-02-12, 5:56 pm

I have a`scrpt that does a numer of operations on a dated log file
(filename-2006-02-29.log). This works well for a single file, but I
would like to run the script to parse log files for the last seven
days. Is there a way I ca do this using `date` so that given today's
date, the script will start seven days back?

Thanks.

Morty

Janis Papanagnou

2006-02-12, 5:56 pm

morty3e@gmail.com wrote:
> I have a`scrpt that does a numer of operations on a dated log file
> (filename-2006-02-29.log). This works well for a single file, but I
> would like to run the script to parse log files for the last seven
> days. Is there a way I ca do this using `date` so that given today's
> date, the script will start seven days back?
>
> Thanks.
>
> Morty
>


If you can use GNU date...

date +filename-%Y-%m-%d.log --date "7 days ago"

....otherwise there are solutions in the FAQ.

Janis
Bill Marcum

2006-02-12, 5:56 pm

On 12 Feb 2006 07:37:03 -0800, morty3e@gmail.com
<morty3e@gmail.com> wrote:
> I have a`scrpt that does a numer of operations on a dated log file
> (filename-2006-02-29.log). This works well for a single file, but I
> would like to run the script to parse log files for the last seven
> days. Is there a way I ca do this using `date` so that given today's
> date, the script will start seven days back?
>


If you don't have GNU date, you could use something like
find . -name '*.log' -mtime -8 | while read file; do
do_something_with "$file"
done


--
Life is NP-hard, and then you die.
-- Dave Cock
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com