我可以看到这是“常见”错误,但在我的情况下无法找到解决方案...
使用以下命令运行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
你可以帮我解决一下这个问题吗?非常感谢你提前!
答案 0 :(得分:19)
您必须转义%
字符。 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.
答案 1 :(得分:1)
尝试逃避%
并且不要使用反引号来填充date
- 命令。请用$()
:
expr $(date +\%W) % 2 > /dev/null && curl https://mysite.com/myscript
OR
expr $(date +\%W % 2) > /dev/null && curl https://mysite.com/myscript