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

拈花ヽ惹草 提交于 2019-12-04 00:28:49

问题


I created a new task in crontab as shown below :

*/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.


回答1:


The problem is that cron treats % as newlines. From crontab POSIX man page:

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 Substitution syntax 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')


来源:https://stackoverflow.com/questions/42241371/bin-sh-1-syntax-error-eof-in-backquote-substitution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!