bash /bin/sh: 1: 语法错误:反引号替换中的 EOF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42241371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:46:29  来源:igfitidea点击:

/bin/sh: 1: Syntax error: EOF in backquote substitution

bashcronubuntu-14.04crontab

提问by Vicky

I created a new task in crontab as shown below :

我在 crontab 中创建了一个新任务,如下所示:

*/2 * * * *       mongodump --db prodys --out /backup/databases/mongoDatabases/`date +"%m-%d-%y"`

I'm getting following error :

我收到以下错误:

/bin/sh: 1: Syntax error: EOF in backquote substitution

Please help, I don't have any clue whats wrong.

请帮忙,我不知道出了什么问题。

回答by Inian

The problem is that crontreats %as newlines. From crontab POSIX manpage:

问题是它被cron视为%换行符。从crontab POSIX man页面:

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.

命令中的百分号 (%) 除非用反斜杠 \ 转义,否则将更改为换行符,并且第一个 % 之后的所有数据将作为标准输入发送到命令。

Also use Command Substitutionsyntax as $()over the legacy `` syntax as

还使用命令替换语法作为$()传统的 `` 语法作为

You could change your command to something like,

您可以将命令更改为类似的内容,

*/2 * * * *       mongodump --db prodys --out /backup/databases/mongoDatabases/$(date +'\%m-\%d-\%y')