[Solved] cron job fails, but command in crontab succeeds when directly entered
Hello,
I have the following crontab listing:
00 04 * * * mysqldump -p<blah> <dbname> > /root/mydb-`date +%Y-%m-%d`.sql; gzip -f /root/mydb-`date +%Y-%m-%d`.sql; smbclient //mynetwork-dc/MySQLBackups <moreblah> -Usqlbackups -c "put mydb-`date +%Y-%m-%d`.sql.gz"
Leaving aside the kludgy nature of this for now, if i run the whole silly command directly, it works perfectly in just a few seconds. The DB is dumped, zipped, and thrown over the network to the target drive, where it lands safely.
When the cronjob runs, however, it chokes. I get this in the logs:
(root) CMD (mysqldump -p<blah> <dbname> > /root/mydb-`date +)
it eats it on the percentage sign. Now, inside the backtics, directly entered, it executes the command and substitutes the result as you'd expect. I have not yet been able to figure out a quoting scheme inside the crontab, however, that works. It dies there every time. i don't get it o_O.
TIA, and Halp!,
Rob
SOLUTION:
Assumed it was quoting, when i shoulda been escaping. Solution was to backslash the percent signs, thusly:
00 04 * * * mysqldump -p<blah> <dbname> > /root/mydb-`date +\%Y-\%m-\%d`.sql; gzip -f /root/mydb-`date +\%Y-\%m-\%d`.sql; smbclient //mynetwork-dc/MySQLBackups <moreblah> -Usqlbackups -c "put mydb-`date +\%Y-\%m-\%d`.sql.gz"
and, while even uglier than before, works perfectly and consistently.
Last edited by rmunsch; 02-16-2009 at 06:43 PM.
Reason: Solved
|