2017-02-15 26 views
8

我創建了crontab中一個新的任務,如下圖所示:/bin/sh的:1:語法錯誤:EOF在反引號替換

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

我收到以下錯誤:

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

請幫助,我不知道什麼是錯的。

回答

7

問題是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.

還可以使用Command Substitution語法$()在傳統``語法

你可以你的命令更改爲類似,

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

謝謝! @Inian這也正是我的問題。 – ShahNewazKhan

+0

謝謝,它有很多幫助! –

相關問題