如何每 72 分钟执行一次 cron 作业 [英] How to do a cron job every 72 minutes
问题描述
我如何获得每 72 分钟运行一次的 cron 作业?或者一些不那么漂亮的数字?
由于 cron
运行基于时间的作业,而不是基于间隔的,因此没有非常简单的方法来做到这一点.但是,尽管这有点小技巧,但您可以在 crontab
中设置多行,直到找到公分母.由于您希望作业每 72 分钟运行一次,因此它必须在以下时间执行:
- 00:00
- 01:12
- 02:24
- 03:36
- 04:48
- 06:00
- 07:12
- ...
如您所见,该模式每 6 小时重复一次,有 5 个作业.因此,您的 crontab
中将有 5 行:
当然,另一种选择是创建一个包装守护进程或 shell 脚本,在所需的时间内执行和休眠直到停止.
How would I get a cron job to run every 72 minutes? Or some not so pretty number like that?
Since cron
runs jobs time-based, not interval-based, there's no blindingly simple way to do it. However, although it's a bit of a hack, you can set up multiple lines in crontab
until you find the common denominator. Since you want a job to run every 72 minutes, it must execute at the following times:
- 00:00
- 01:12
- 02:24
- 03:36
- 04:48
- 06:00
- 07:12
- ...
As you can see, the pattern repeats every 6 hours with 5 jobs. So, you will have 5 lines in your crontab
:
0 0,6,12,18 * * * command 12 1,7,13,19 * * * command 24 2,8,14,20 * * * command 36 3,9,15,21 * * * command 48 4,10,16,22 * * * command
The other option, of course, is to create a wrapper daemon or shell script that executes and sleeps for the desired time until stopped.
这篇关于如何每 72 分钟执行一次 cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!