我在运行 RedHat 4.1 的服务器上设置了一个 cron 作业来备份 MySQL 数据库,然后上传到 Amazon S3。目标是将 .bz2 文件放入与星期几对应的文件夹中。但是,我收到了守护进程邮寄给我的以下错误。
定时任务:
MAILTO=backups@example.com
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
Run Code Online (Sandbox Code Playgroud)
错误信息:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
Run Code Online (Sandbox Code Playgroud)
Ser*_*sov 22
您需要使用反斜杠对命令中的百分号进行转义:\%,否则将其解释为命令的结尾。
来自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.
Run Code Online (Sandbox Code Playgroud)
改变这个:
`date +%A`
Run Code Online (Sandbox Code Playgroud)
到:
`date +\%A`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5571 次 |
| 最近记录: |