“在cron作业上寻找匹配的”`“时意外的EOF

我在运行RedHat 4.1的服务器上设置了一个cron作业来备份MySQL数据库,然后上传到Amazon S3。 目标是将.bz2文件放在与一周中某一天对应的文件夹中。 但是,我收到了以下由守护进程邮寄给我的错误。

克朗工作:

[email protected] 0 4 * * * mysqldump --all-databases -ubackups -pPassword | gzip > all-databases.sql.bz2; s3cmd put all-databases.sql.bz2 s3://backup_exampleserver.com/mysql_backups/`date +%A`/all-databases.sql.bz2 

错误信息:

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

您需要使用反斜杠: \%来转义命令中的百分号,否则将被解释为命令的结尾。

crontab (5):

 The command field (the rest of the line) is the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab. Percent signs ('%') in the command, unless escaped with a backslash ('\'), will be changed into newline characters, and all data after the first '%' will be sent to the command as standard input. 

改变这个:

 `date +%A` 

至:

 `date +\%A`