Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Mar 2022 14:21:08 +0000
From:      Arthur Chance <freebsd@qeng-ho.org>
To:        Steve O'Hara-Smith <steve@sohara.org>, Jos Chrispijn <bsduser@cloudzeeland.nl>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Crontab | random execution time
Message-ID:  <757693ff-bc0a-5941-94e1-b59798ff0370@qeng-ho.org>
In-Reply-To: <20220307141454.91255883d98dd7b980e6fc22@sohara.org>
References:  <9e16ee69-3793-41f5-385f-71d87dedcf2c@cloudzeeland.nl> <20220307141454.91255883d98dd7b980e6fc22@sohara.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 07/03/2022 14:14, Steve O'Hara-Smith wrote:
> On Mon, 7 Mar 2022 14:36:19 +0100
> Jos Chrispijn <bsduser@cloudzeeland.nl> wrote:
> 
>> Dear list,
>> I am trying to run a cron job, starting once every two hours and at 
>> random minute  in the half our of that cron scheme:
>>
>> SHELL=/bin/sh
>> PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/etc
>> 0~30   */2     *       *       *       root /root/cronjobs/run_myjob
>>
>> Unfortunately it is running exactly on the hour instead of random 
>> between 0-30 minutes.
> 
> 	I'd expect that to run once a minute for the first thirty minutes
> of even numbered hours.
> 
> 	The usual way to achieve what you want is to add a random sleep in
> front of the job, or just rely on cron's jitter feature which isn't usually
> set for that much spread and affects every job.
> 

That line has a '~' in it which isn't a documented form. I suspect cron
 reads it as '0'.

To do a random sleep of 0-30 minutes add

	sleep `jot -r 1 0 1800`

to the start of your command.

-- 
All network cabling aspires to the condition of macramé.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?757693ff-bc0a-5941-94e1-b59798ff0370>