在 crontab 中出现错误时间错误

Hac*_*ker 0 cron

我收到以下 crontab 条目的错误时间错误:

*/05 17-05 * * * wget -q -O /dev/null "http://abcd/cron/abcd"
Run Code Online (Sandbox Code Playgroud)

这有什么问题吗?我希望 cron 从晚上 5 点运行到早上 5 点

Ouk*_*uki 5

由于您没有指定您使用的是哪个系统,我希望您的系统使用“Vixie”或“Vixie”相关的 crontab 实用程序。

仍然:

  • 17-05: 不被认为是合适的范围(下限大于范围的上限)。

你可以改写:“ 17-23,00-05

来自man 5 crontab

 Ranges of numbers are allowed.  Ranges are two numbers separated with a
hyphen.  The specified range is inclusive.   For example, 8-11 for an
``hours'' entry specifies execution at hours 8, 9,  10 and 11.
Run Code Online (Sandbox Code Playgroud)

所以,确定没有什么真正禁止你像你那样写一个间隔。

关于其他 crontab 实用程序如何允许您指定的不仅仅是一个简单的范围(您的系统可能是其中之一),Extensions部分man 5 crontab也很有趣:

 Lists and ranges are allowed to co-exist in the same field.
 "1-3,7-9" would be rejected by ATT or BSD cron -- they want to
see "1-3" or "7,8,9" ONLY.
Run Code Online (Sandbox Code Playgroud)

因此,如您所见,这实际上取决于您的系统 crontab 是否能够理解“ 17-05”的含义。

想要查询更多的信息: