每 N 分钟加上偏移量运行一次 Cron 作业 [英] Run Cron job every N minutes plus offset

查看:22
本文介绍了每 N 分钟加上偏移量运行一次 Cron 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*/20 * * * *

确保它每 20 分钟运行一次,我想每 20 分钟运行一次任务,从每小时 5 点开始,这可以用 Cron 实现吗?会不会是:

Ensures it runs every 20 minutes, I'd like to run a task every 20 minutes, starting at 5 past the hour, is this possible with Cron? Would it be:

5/20 * * * * ?

推荐答案

要从每小时 5 点开始每 20 分钟运行一次任务,试试这个:

To run a task every 20 minutes starting at 5 past the hour, try this:

 5-59/20 * * * *

说明

分钟字段中的 *0-59/1 相同,其中 0-59range1步骤.该命令将在 range (0) 的第一分钟运行,然后在距离第一分钟 step (1) 的所有连续分钟内运行,直到最后一个 (59).

An * in the minute field is the same as 0-59/1 where 0-59 is the range and 1 is the step. The command will run at the first minute in the range (0), then at all successive minutes that are distant from the first by step (1), until the last (59).

这就是为什么 */20 * * * * 将在 0 分钟、20 分钟后和 40 分钟后运行 - 这与每 20 分钟相同.但是,*/25 * * * * 将在 0 分钟、25 分钟后和 50 分钟后运行——这与每 25 分钟不同.这就是为什么通常希望在分钟字段中使用一个步长值,将其平均分为 60.

Which is why */20 * * * * will run at 0 minutes, 20 minutes after, and 40 minutes after -- which is the same as every 20 minutes. However, */25 * * * * will run at 0 minutes, 25 minutes after, and 50 minutes after -- which is not the same as every 25 minutes. That's why it's usually desirable to use a step value in the minute field that divides evenly into 60.

因此要偏移开始时间,请明确指定范围并将第一个值设置为偏移量.

So to offset the start time, specify the range explicitly and set the first value to the amount of the offset.

示例

5-59/20 * * * * 将在 5 分钟后、25 分钟后和 45 分钟后运行.

5-59/20 * * * * will run at 5 minutes after, 25 minutes after, and 45 minutes after.

10-59/25 * * * * 将在 10 分钟后和 35 分钟后运行.

10-59/25 * * * * will run at 10 minutes after and 35 minutes after.

1-59/2 * * * * 将每隔奇数分钟运行一次.

1-59/2 * * * * will run every odd minute.

这篇关于每 N 分钟加上偏移量运行一次 Cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆