@hourly vs 0 * * * * - Cron - How to run jobs hourly, but at different times
From crontab(5)
:
@hourly
: Run once an hour, ie."0 * * * *"
.
So it's strictly the same.
To run a job at a varying point in the hour (or multiple jobs, to spread the load) you can sleep for a random amount of time before starting the job:
@hourly sleep $((RANDOM / 10)); dowhatever
This sleeps for up to 3276 seconds (nearly an hour), then runs the job. So every time cron
starts the job, it waits a different amount of time before actually starting.
@hourly
is an exact synonym of 0 * * * *
in crontab
, there is no difference. @hourly
is a special string representation for 0 * * * *
.
From man 5 crontab
:
string meaning
------ -------
@hourly Run once an hour, "0 * * * *".
Just to note, there are 8 special strings in total supported by the cron
i have, Vixie Cron.
Just wanted to share Jenkins Cron/Build Periodically Methodology. Would be nice to see something like this in regular Cron where H(hash) was an option
Examples:
# every fifteen minutes (perhaps at :07, :22, :37, :52)
H/15 * * * *
# every ten minutes in the first half of every hour (three times, perhaps at :04, :14, :24)
H(0-29)/10 * * * *
# once every two hours at 45 minutes past the hour starting at 9:45 AM and finishing at 3:45 PM every weekday.
45 9-16/2 * * 1-5
# once in every two hours slot between 9 AM and 5 PM every weekday (perhaps at 10:38 AM, 12:38 PM, 2:38 PM, 4:38 PM)
H H(9-16)/2 * * 1-5
# once a day on the 1st and 15th of every month except December
H H 1,15 1-11 *