LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2005, 03:01 PM   #1
sammysrefuge
LQ Newbie
 
Registered: Mar 2005
Posts: 2

Rep: Reputation: 0
Question How do I add the current date to a filename?


I am trying to set up a cron job to automatically zip my logs at the end of each day. I had someone set up a cron job for me to tar the logs but it isn't compressing the logs well enough.

What I want to be able to do is to run a command that takes a specific file and zip it into another file that includes the current date. For example: Take the file log.daily and zip it into a file daily.log.03.18.05.zip (assuming that todays date is March 18, 2005)

I have tried accomplishing this a number of ways. Here is one method I have tried:

zip /usr/local/apache/logs/daily.log.'date +\%m.\%d.\%y'.zip /usr/local/apache/logs/*.daily

The end result of this command is a file named daily.log.date +\%m.\%d.\%y.zip

The desired result again would be a file named daily.log.03.18.05.zip. I know this is possible, but I just don't know the correct syntax.

I would appreciate any help that you can give me.

Thanks in advance,

Jason
 
Old 03-18-2005, 03:09 PM   #2
houdelou
Member
 
Registered: Nov 2004
Location: Canada
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 15
try this :

zip /usr/local/apache/logs/daily.log.$(date +\%m.\%d.\%y').zip /usr/local/apache/logs/*.daily

the only difference is that I enclose the command between $(command) instead of 'command'
 
Old 03-18-2005, 03:43 PM   #3
sammysrefuge
LQ Newbie
 
Registered: Mar 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Works Great!

Thanks for your help.

Jason
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
logrotate with date in filename ptp Linux - Newbie 1 04-14-2011 11:55 AM
using bash in cron to get the date in filename rstoutmna Programming 1 12-29-2004 03:39 PM
Script add date to filename amphion Linux - Newbie 2 06-02-2004 08:12 AM
use date as output filename? wijnands Linux - Newbie 1 05-12-2004 04:39 PM
how to add date to filename x2000koh Programming 1 07-08-2003 10:44 PM


All times are GMT -5. The time now is 02:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration