The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cron job - appending date to file name

Discussion in 'General Discussion' started by workshop, Dec 30, 2011.

  1. workshop

    workshop Member

    Joined:
    Sep 21, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I currently have a cron job to zip the contents of a folder (which I will ftp for backup purposes).

    This works fine - but I would like to append the date to the file name.

    I have tried various iterations of the $(date +.... command , but can't get it to work.

    Anybody got any ideas....?

    Here is my current cron command...

    tar -cvf /home/accountname/public_html/backup/mybackup.tar /home/accountname/public_html/myfolder

    which works fine - but obviously each time it runs it overwrites the existing file

    I need something like

    tar -cvf /home/accountname/public_html/backup/mybackup_$(date +%D%Y%M).tar /home/accountname/public_html/myfolder

    But whatever I try doesn't result in any file being created.

    Am I missing something or is this not possible?

    Any help, much appreciated.

    Thanks.
     
  2. workshop

    workshop Member

    Joined:
    Sep 21, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Fixed it!!!!

    You need to "escape" the % sign with a \

    so filename_$(date +\%d\%m\%Y).tar

    Seems to work.
     
Loading...

Share This Page