【问题标题】:Running cron job creates an error unexpected EOF while looking for matching ``'运行 cron 作业会在查找匹配的 ``' 时创建错误的意外 EOF
【发布时间】:2012-06-25 11:33:02
【问题描述】:

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

运行 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

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

【问题讨论】:

    标签: cron crontab cron-task


    【解决方案1】:

    您必须转义 % 字符。 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.
    

    【讨论】:

    • 这一点小知识对我帮助很大。我无法理解为什么date +%Y-%m-%d_%H-%M-%S 在脚本中完美运行,但在(菊花链式 crontab)命令行中却不行。谢谢丹尼尔!
    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 2019-01-19
      相关资源
      最近更新 更多