Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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. –  FractalizeR 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

3 Answers 3

up vote 2 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? –  FractalizeR 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 script.sh

#!/bin/bash

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/script.sh
share|improve this answer

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