Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Possible Duplicate:
escaping double quotes and percent signs (%) in cron

I have the following command in cron:

5 6 * * * bash -c "tar -czf /backups/sites-server-files-rotate/sites_`date +%F`.tar.gz /backups/sites-server-files/"

But command doesn't get executed. And I can see the following in the cron log:

Apr 17 06:05:01 backup crond[9423]: (root) CMD (bash -c "tar -czf /backups/sites-server-files-rotate/sites_`date +)

It seems like % sign cuts the command in cron. Why? Do I have to escape it? And how?

share|improve this question

marked as duplicate by Kyle Smith, Khaled, mulaz, Ward, Magellan Oct 17 '12 at 16:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

@Kyle Smith Someone needs to rename that post to include % also. One can't find it using search. – Vladislav Rastrusny Apr 17 '12 at 11:34
Done. Though, I'm not sure you can search for a '%'. – Kyle Smith Apr 17 '12 at 12:18
up vote 3 down vote accepted

Yes you do have to escape it. A backslash will do.

You can also put the command in a script and call the script instead.

share|improve this answer

Yes, you need to escape it. Just type \ backslash before every occurrence of %.

The percent character indicates new line in crontab.

share|improve this answer
What special meaning has % in cron? Or in shell? – Vladislav Rastrusny Apr 17 '12 at 11:03

You can make a bash file with your script and then add it to crontab.

For example : make file


tar -czf /backups/sites-server-files-rotate/sites_\`date +%F\`.tar.gz /backups/sites-server-files/

Then add to cron:

5 6 * * * /dir/to/your/
share|improve this answer

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