Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron error with using backquotes

Tags:

linux

shell

cron

The following works fine from command line

/usr/bin/mysqldump -uUser -pPass Db_name > /var/www/db_backup/db.`date +%Y%m%d%H%M`.sql 

but when I try to do that in cron, I get the error:

bad ` sign 
errors in crontab file, can't install

I saw someone else on the net solve the same problem by escaping the percent signs, but that didn't help and I tried it with just date inside backquotes with no format specifiers and still got the errors.

I've also seen date's argument enclosed in single or double quotes, but that doesn't help either.

Granted I could just throw it into a script and execute that I suppose - but what fun is that?

Any ideas? I'm using RHEL 5.

like image 248
amac44 Avatar asked Aug 09 '10 22:08

amac44


1 Answers

Try it with $() instead of backticks. And you probably do need to escape the percent signs since cron converts them to newlines otherwise.

* 0 * * * /usr/bin/mysqldump -uUser -pPass Db_name > /var/www/db_backup/db.$(date +\%Y\%m\%d\%H\%M).sql

Also, you should store the password in an option file with secure permissions (eg. 600 or 640) instead of passing it on the command line.

like image 178
Dennis Williamson Avatar answered Oct 06 '22 22:10

Dennis Williamson