10

我可以看到这是“常见”错误,但在我的情况下找不到解决方案......

运行 crontab 作业:

expr `date +%W` % 2 > /dev/null && curl https://mysite.com/myscript

它会导致错误:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

你能帮我如何避免它们吗?非常感谢您!

4

2 回答 2

21

你必须逃避这个%角色。man 5 crontab说:

   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.
于 2012-07-22T16:44:45.013 回答
2

尝试转义%并且不要使用反引号来包含date-command。请附上$()

expr $(date +\%W) % 2 > /dev/null && curl https://mysite.com/myscript

或者

expr $(date +\%W % 2) > /dev/null && curl https://mysite.com/myscript
于 2014-03-03T17:35:04.517 回答