简体   繁体   中英

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

Why is my cron task giving me a 'bad hour' error.

Below is my cron task (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.

I'm running my cron crontab mycron.txt

Cron expression ideally,should be:

  1. To run from midnight to 12 noon every 15 minutes:

     */15 00-12 * * *

(or)

  1. To run from 12 noon to midnight every 15 minutes.

     */15 00,12-23 * * *

The following crontab will run every 15 minutes from 12:00 onwards till 00:00 but excluding 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. 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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