[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Creating a randomized cron entry



On Thu, Dec 15, 2005 at 12:55:00PM +0000, Stephen Gran wrote:
> This one time, at band camp, Don Armstrong said:
> > On Thu, 15 Dec 2005, Florian Weimer wrote:
> > > I'd like to create a cron entry which is run once a day, at some
> > > random time.  This is necessary because the cron entry will result
> > > in a request over the network, and I want to avoid that all hosts in
> > > a time zone pound the server at the same time.
> > 
> > Why not just something like:
> > 
> > 0 0 * * * at now + $(( $RANDOM \% 1440 )) minutes [...]
> 
> Because that's a bashism, and some dash user will get upset with you.
> 
> Probably the most portable way to handle it is to run the job from
> cron.daily, but call a wrapper script that sleeps for a random amount of
> time less than one day before runnign the actual job.  For extra
> goodness, use a lock file so that if the last random sleep was 23 hours
> and 59 minutes, and the next one is 1 minute, you don't two jobs at
> once.
But that means essentially running a daemon for the package,
completely undermining the point of cron.

-- 
Clear skies,
Justin



Reply to: