Cron */6 hours but with an offset

cron

I have a bunch of devices all running a similar cron job. Currently I'm setting a cron minute and hours to a random number (that way they don't all run at once).

$random_minute $random_hour * * * sudo /bin/script

I want to keep this pattern of making each device random but I also have a script which needs to be run every 6 hours. How can I combine something like above with */6?

Best Answer

There aren't that many hours in the day, so why not just

17 3,9,15,21 * * * sudo /bin/script

to run at 03:17 and every 6 hours hence?

The alternatives would involve adding a sleep to the program itself:

0 */6 * * * (sleep 11820; sudo /bin/script)

or running the script more often (say, hourly), and having the script just exit if the actual job was executed within the last < 6 hours.

Related Question