Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make a cron job that creates a tar of my web directory.

I have this job in place

* * * * * tar -zcvfp /disk1/archives/websites/`date +%Y-%m-%d_%I-%M-%S-%p`/`date +%Y-%m-%d_%I:%M:%S:%p`.tar.gz /web

this job SHOULD (but doesn't) create a tar file to my /disk1... directory. so I'm stumped on that one.

another thing that has been on my mind is, is it possible to make all backup tar file get dumped into a date +%Y-%m-%d and have all files that were created on that same day be placed there?

So an output would look like


I have made this job run every minute for test purposes.

Is there anything wrong with my syntax?

share|improve this question
up vote 2 down vote accepted

cron does not know what tar or date is because it doesn't have environment variables. Reffer to the binaries using their full path.

If you don't know the full path, use which to get it.


[bart@dev ~]$ which tar
[bart@dev ~]$ which date

This would make your cron-line this:

/bin/tar -zcvfp /disk1/archives/websites/`/bin/date +%Y-%m-%d_%I-%M-%S`/`/bin/date +%Y-%m-%d_%I:%M:%S`.tar.gz /web
share|improve this answer
thanks, ya its late... i need sleep, your 100% right. I forgot to insert the path of the command i'm trying to run. – s2xi Feb 5 '12 at 13:56

Put your tar inside a shell script, say, /usr/local/bin/ Then call that script from cron.

* * * * * /usr/local/bin/

The trick is that cron is not a shell, so things that work in shell expansion may not work in crontabs. It's much, much safer and easier to debug to put your commands into a script, and then call that script (by it's full path).

share|improve this answer
You would still need to include full paths to binaries or but bash in front of your script so it would load a shell for it. – Bart De Vos Feb 5 '12 at 14:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.