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.

I set up a cron job on my server running RedHat 4.1 to backup MySQL databases, and then upload to Amazon S3. The goal is to drop the .bz2 file in a folder corresponding with the day of the week. However, I'm getting the following error mailed to me by daemon.

Cron job:

MAILTO=backups@example.com
0       4       *       *       *       mysqldump --all-databases  -ubackups -pPassword | gzip > all-databases.sql.bz2; s3cmd put all-databases.sql.bz2 s3://backup_exampleserver.com/mysql_backups/`date +%A`/all-databases.sql.bz2

Error message:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
share|improve this question
1  
I recommend to put this stuff in a regular shell script and then call this shell script from cron. This way, you can save you a lot of trouble and make the job a lot easier to understand and debug. –  Sven Sep 12 '12 at 13:35

2 Answers 2

up vote 5 down vote accepted

You need to escape the percent sign in your command with a backslash: \%, otherwise it is interpreted as the end of command.

From crontab(5):

The command field (the rest of the line) is the command to be run.  The
entire command portion of the line, up to a newline or % character, will
be executed by /bin/sh or by the shell specified in the SHELL variable of
the crontab.  Percent signs (‘%’) in the command, unless escaped with a
backslash (‘\’), will be changed into newline characters, and all data
after the first ‘%’ will be sent to the command as standard input.
share|improve this answer
    
Awesome, thank you for the clarification. New to cron, so much appreciated! –  Jamie - eyespeak Sep 12 '12 at 13:43

Change this:

`date +%A`

to:

`date +\%A`
share|improve this answer
    
Thanks for the help! –  Jamie - eyespeak Sep 12 '12 at 13:43

Your Answer

 
discard

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.