运行cron作业时会在查找匹配的``'时创建错误的意外EOF

use*_*003 10 cron crontab cron-task

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

运行Crontab作业:

expr `date +%W` % 2 > /dev/null && curl https://mysite.com/myscript
Run Code Online (Sandbox Code Playgroud)

它会导致错误:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
Run Code Online (Sandbox Code Playgroud)

你能帮我解决一下吗?非常感谢你提前!

Dan*_*kov 20

你必须逃脱这个%角色.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.
Run Code Online (Sandbox Code Playgroud)

  • 这一小小的知识对我帮助很大.我无法理解为什么`date +%Y-%m-%d_%H-%M-%S`在脚本中完美地工作但在(菊花链式crontab)命令行中不能工作.谢谢Daniel! (2认同)