|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
crontab mysqldump syntax
I am trying to make a simple cron script to backup my db using mysqldump. I am entering the script via crontab in plesk.
here is the script: mysqldump -ufred -p***** email_list2 > /home/httpd/vhosts/mySite.com/httpdocs/dump_`date +%d%m%Y_%H%M`.txt It works great when i run it at the command line. But, when run via cron i get this error: /bin/sh: -c: line 1: unexpected EOF while looking for matching ``' /bin/sh: -c: line 2: syntax error: unexpected end of file Also, if I remove the `date +%d%m%Y%H%M` it works too. Have read many threads, and it seems that this is the syntax people are using. Any thoughts? thanks. |
|
#2
|
|||
|
|||
|
What shell?
Just out of curiousity, what shell are you using to run it when you run it manually?
Maybe that shell handles the ' ` characters differently than /bin/sh (which is what it looks like cron is using). I don't know for sure, I'm mostly guessing based on the context of the error. Try switching to /bin/sh yourself and run the line manually and see if it still works. |
|
#3
|
|||
|
|||
|
Check cron environment variables of SHELL, HOME etc there. Try to export other variables on cron script itself.
Try as, FILE="/home/httpd/vhosts/mySite.com/httpdocs/dump_$(date +%d%m%Y_%H%M).txt" mysqldump -ufred -p***** email_list2 > $FILE Try this out. And tell. HTH. |
|
#4
|
|||
|
|||
|
use the full path
Typically the path in cron is /usr/bin and /usr/sbin so it can't find the date function. Use /bin/date instead and you should be OK.
|
|
#5
|
|||
|
|||
|
If you run that exact command from cron it will not work as cron does not know how to cope with things like `date ...`. You would need to put the actual command within a wrapper script.
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop |
|
#6
|
|||
|
|||
|
You can use date from within cron
Quote:
In fact you can use any command as you would from the command-line. You have to be careful with escapes and quotes but it all works. Here is a working example of what I use to automate a myldump with cron: 58 13 * * 2,5 mysqldump --user=user --password=pass --host=127.0.0.1 mydb > /var/backups/mydb-`/bin/date +\%Y\%m\%d` For example, yesterday (Tuesday) at 1:58 PM, it dumped the sql to /var/backups/mydb-20080506 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > crontab mysqldump syntax |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|