Super User is a question and answer site for computer enthusiasts and power users. 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

I am trying to schedule a MySQL database dump by using cron but I get an error for some code that I know works when I call directly in Shell.

Here is the code that works perfectly well in Shell:

mysqldump -uUSER -pPASS DB > "/path/to/backup/backup_`date +%Y%m%d%H%M%S`.sql"

However when I set a cron job up it comes back with the following error:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

Please can someone tell me what I am doing wrong?

Cheers, Ian.

share|improve this question
up vote 2 down vote accepted

Try:

mysqldump -uUSER -pPASS DB > /path/to/backup/backup_`date +"\%Y\%m\%d\%H\%M\%S"`.sql

an easier solution in the future would be to place your command which works in bash, into a shell script, then run the shell script from cron. If it works in bash, it will work in a shell script.

share|improve this answer
    
Forgot to escape again didn't I! Thanks for your help. – Ian Dec 15 '09 at 12:32
    
Common mistake. Any time :) – John T Dec 15 '09 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .