如何从0分钟以外的时间开始每5分钟运行一次 cron 作业?

我想有一个脚本运行每5分钟,让我们说从13:02开始,这样我可以有另一个脚本运行每5分钟,但从13:04开始,所以第二个脚本运行两分钟后,第一个作业开始。我怎么才能做到呢?

90481 次浏览

Syntax 1

*/5+2 * * * * 1st-script
*/5+4 * * * * 2nd-script

For future reference take a look at this online Cron Job Generator.

Syntax 2

Since there are several reports that the + syntax is not working on Ubuntu 14.04, here's a variation:

2-59/5 * * * * 1st-script
4-59/5 * * * * 2nd-script

This will result in the 1st script to run every 5 minutes starting with an offset of 2 minutes at the beginning of each hour and the 2nd script to behave the same with an offset of 4 minutes.

*/5+1 * * * * first_script.sh

To run every five minutes, but offset one minute

or

*/5 * * * * sleep 120; ( first_script.sh & ) ; sleep 120 ; second_script.sh

nice thing about this approach is that you can let crontab start things at times other then minute boundaries (like 30 seconds after the hour)

I needed similar thing - to execute script every 5 minutes starting from third minute of an hour. I doubted above solutions (because website crontab.guru was convincing me about invalid syntax) and so my colleague told me to specify minutes directly like this:

3,8,13,18,23,28,33,38,43,48,53,58 * * * *

Its list of concrete minutes.