ChatGPT解决这个技术问题 Extra ChatGPT

How can I run a cron job every 5 minutes starting from a time other than 0 minutes?

I would like to have a script run every 5 minutes let's say starting from 13:02 so I can have another script runs every 5 minutes but starting from 13:04 so the second script runs two minutes after the start of the first job. How can I achieve this?


m
mwfearnley

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.


@xtian, please take a look at the alternative solution I've added and let me know if it works as expected.
My cPanel (version 11.52) doesn't seem to accept none of those syntaxes. I've solved with 1,6,11,16,21,26,31,36,41,46,51,56 * * * * php ...
Same issue in Ubuntu 16.04. The original answer doesn't work but the updated version does
The cron in RHEL 6.10 doesn't like */5+2 either, but 2-59/5 works like a champ.
The updated version with 2-59/5 is needed for Firebase scheduled functions too. tnx
E
Emile Aben

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)


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

To run every five minutes, but offset one minute


A
Ales

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.