Unix questions - Saving files including current date variable in filename

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > December 2007 > Saving files including current date variable in filename





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 Saving files including current date variable in filename
Fred

2007-12-15, 7:31 am

Perhaps someone can advise me how to best do the following?

I'd like a cron job on a BSD machine to once a month save the server access
log files in the following format:

access_DDMMYY.txt

If I simply type the 'date' command into the shell I get the following type
of output:
Sat Dec 15 11:41:37 GMT 2007

Does anyone have a smart procedure that can rename the file named
"access.log" into "access_151107.txt" if the command ran today for example?


Fred

2007-12-15, 7:31 am

I wrote:
> "access.log" into "access_151107.txt" if the command ran today for


I meant "access_151207.txt" of course...


Bit Twister

2007-12-15, 1:20 pm

On Sat, 15 Dec 2007 12:50:10 +0100, Fred wrote:
>
> If I simply type the 'date' command into the shell I get the following type
> of output:
> Sat Dec 15 11:41:37 GMT 2007


Here try this
date +%Y-%m-%d
then try
man date

Fred

2007-12-15, 1:20 pm

Bit Twister wrote:

> On Sat, 15 Dec 2007 12:50:10 +0100, Fred wrote:
>
> Here try this
> date +%Y-%m-%d
> then try
> man date
>


Perfect - thanks for the tip!

s. keeling

2007-12-15, 1:20 pm

Bit Twister <BitTwister@mouse-potato.com>:
> On Sat, 15 Dec 2007 12:50:10 +0100, Fred wrote:
>
> date +%Y-%m-%d
> then try
> man date


Where you'll find %F.

(0) heretic /home/keeling_ date +%F
2007-12-15

For datestamping files, I prefer +%Y%m%d


--
Any technology distinguishable from magic is insufficiently advanced.
(*) http://blinkynet.net/comp/uip5.html Linux Counter #80292
- - http://www.faqs.org/rfcs/rfc1855.html Please, don't Cc: me.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com