简体   繁体   English

为什么我在 cron 任务中收到“糟糕的时间”错误?

[英]Why am I receiving a 'bad hour' error in my cron task?

Why is my cron task giving me a 'bad hour' error.为什么我的 cron 任务给我一个“糟糕的时间”错误。

Below is my cron task (mycron.txt) :下面是我的 cron 任务(mycron.txt)

*/15 12-00 * * * php mycommand.php: bad hour errors in crontab file, can't install.

What I want is to run my PHP script every 15 minutes, every day from 12PM to midnight.我想要的是每天从中午 12 点到午夜每 15 分钟运行一次我的 PHP 脚本。

I'm running my cron crontab mycron.txt我正在运行我的 cron crontab mycron.txt

Cron expression ideally,should be:理想情况下,Cron 表达式应该是:

  1. To run from midnight to 12 noon every 15 minutes:从午夜到中午 12 点每 15 分钟运行一次:

     */15 00-12 * * *

(or) (或者)

  1. To run from 12 noon to midnight every 15 minutes.从中午 12 点到午夜每 15 分钟运行一次。

     */15 00,12-23 * * *

The following crontab will run every 15 minutes from 12:00 onwards till 00:00 but excluding 00:00以下 crontab 将从 12:00 开始到 00:00 每 15 分钟运行一次,但不包括00:00

# Example of job definition:
# .-------------------- minute (0 - 59)
# |    .--------------- hour (0 - 23)
# |    |    .---------- day of month (1 - 31)
# |    |    |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |    |    |  |  .---- day of week (0 - 6) (Sunday=0 or 7)
# |    |    |  |  |
# *    *    *  *  *     command to be executed
*/15 12-23  *  *  *     command

The following crontab will run every 15 minutes from 12:00 onwards till 00:00 but including 00:00.以下 crontab 将从 12:00 开始每 15 分钟运行一次,直到 00:00,但包括00:00。 For this you need two lines!为此,您需要两行!

# Example of job definition:
# .-------------------- minute (0 - 59)
# |    .--------------- hour (0 - 23)
# |    |    .---------- day of month (1 - 31)
# |    |    |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |    |    |  |  .---- day of week (0 - 6) (Sunday=0 or 7)
# |    |    |  |  |
# *    *    *  *  *     command to be executed
*/15 12-23  *  *  *     command
  0    00   *  *  *     command

我对 cronjobs 时间和日期很困惑,这个工具帮了我很多https://crontab.guru/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM