Syntax error only when running cron command

This command:

/usr/bin/mysqldump --add-drop-table -u myuser -pmypass mydb > "/home/myuser/dbBackups/"`date +%Y%m%d`".sql"

works fine from the command line, but when b cron starts it, I get

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

The command is also on the same line in crontab, so the links to lines 0 and line 1 are confusing me ...

Can anyone advise me what I'm doing wrong there?

+3
source share
3 answers

The simplest fix is ​​probably to put the whole command in a shell script and just run it. So create a scriptName.sh file containing the command you specified, and call crontab script. It turns out to be all these odd problems.

+4
source

, backquote crontab (crontab -l)?

, crontab, "" script.

:

, , . crontab (5):

Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the
first % will be sent to the command as standard input.

, , , backquote , .

. , ....

+5

, cron, , . ( ):

/usr/bin/mysqldump --add-drop-table -u myuser -pmypass mydb > "/home/myuser/dbBackups/"`/usr/bin/date +%Y%m%d`".sql"

, , date , which date, , .

+1

Source: https://habr.com/ru/post/1756073/


All Articles