Cron 调度从整小时到半小时

Cron scheduling from whole hour to half

我遇到了问题。我需要将 cron 调度程序设置为每天从早上 8 点到 10:30PM 每分钟开始。谁知道,这可能吗?

要完成此操作,您需要使用一个小技巧:

# .----------------------- 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
  */30    8-22 *  *  *   command

这将在所有请求的时间执行命令。从 08:00AM 开始到 10:30PM(包括 10:30PM)

man 5 crontab: Step values can be used in conjunction with ranges. Following a range with /<number> specifies skips of the number's value through the range. For example, 0-23/2 can be used in the 'hours' field to specify command execution for every other hour (the alternative in the V7 standard is 0,2,4,6,8,10,12,14,16,18,20,22). Step values are also permitted after an asterisk, so if specifying a job to be run every two hours, you can use */2.

您可以播放和测试您的 crontab here