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?


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.

  • hmm, yes and I guess if I want to do that programmatically I can get a random number between 0-5, then $random + 6, $random + 12, $random + 18. Dec 1 '17 at 17:28
  • @PhilipKirkbride, hmm, yes. Though for multiple (almost) identical systems it would probably be easier to keep the crontabs identical, and use some method within the script to choose the delay...
    – ilkkachu
    Dec 1 '17 at 17:31
  • Or something like sleep $(< /etc/cron.delay) ; sudo /bin/script in the crontab...
    – ilkkachu
    Dec 1 '17 at 17:35

With some cron implementations, you can use:

17 3-23/6 * * * * some command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.