0
votes

I am trying to run a cron job to backup my SQL database on a daily basis. This is the code I am using.

/usr/local/mysql/bin/mysqldump -uroot -ppassword --opt database > /path/to/directory/filename.sql    

However, it returns me with the following error:
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file

Wondering what the solution is....

1

1 Answers

0
votes

If you need to use cron with complex shell commands, like with special characters, you should put them in an external script and only call the script in the crontab. This way, you will also be able to run it manually for testing.

Example:

  • Put your command in, for example, /usr/local/sbin/my_backup_script.sh
  • Don't forget to add #!/bin/sh at the top of the sh file
  • Do chmod a+x /usr/local/sbin/my_backup_script.sh
  • Test that running the script manually is doing the job
  • Then add 0 4 * * * root /usr/local/sbin/my_backup_script.sh to the crontab
  • (Or 0 4 * * * /usr/local/sbin/my_backup_script.sh if you are using personal crontab)

(You can replace 0 4 with the time you want it to run, using form "mm hh")