如何做一个cron工作每72分钟 [英] How to do a cron job every 72 minutes
问题描述
我如何获得cron作业,每72分钟运行一次?
How would I get a cron job to run every 72 minutes? Or some not so pretty number like that?
推荐答案
由于 cron
运行工作基于时间,而不是基于时间间隔,没有明显简单的方法。然而,虽然它有点黑客,你可以在 crontab
中设置多行,直到找到公分母。由于您希望每72分钟运行一次作业,因此必须在以下时间执行:
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
- ...
- 00:00
- 01:12
- 02:24
- 03:36
- 04:48
- 06:00
- 07:12
- ...
如您所见,该模式每6小时重复5个作业。因此,您的 crontab
中将有5行:
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
,是创建一个包装器守护程序或shell脚本,执行并睡眠所需的时间,直到停止。
The other option, of course, is to create a wrapper daemon or shell script that executes and sleeps for the desired time until stopped.
这篇关于如何做一个cron工作每72分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!