我在运行 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
答案1
您需要使用反斜杠:来转义命令中的百分号\%
,否则它将被解释为命令的结束。
从定时任务(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.
答案2
改变这个:
`date +%A`
到:
`date +\%A`