From nobody Mon Mar 7 14:21:08 2022 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4A3A11A04AC4 for ; Mon, 7 Mar 2022 14:21:50 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from mailout.qeng-ho.org (mailout.qeng-ho.org [217.155.128.244]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4KC0yP2V49z3J59 for ; Mon, 7 Mar 2022 14:21:49 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from [172.23.1.2] (arthur.home.qeng-ho.org [172.23.1.2]) by mailout.qeng-ho.org (Postfix) with ESMTP id 463D09B66C; Mon, 7 Mar 2022 14:21:08 +0000 (GMT) Message-ID: <757693ff-bc0a-5941-94e1-b59798ff0370@qeng-ho.org> Date: Mon, 7 Mar 2022 14:21:08 +0000 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: Crontab | random execution time Content-Language: en-GB To: Steve O'Hara-Smith , Jos Chrispijn Cc: FreeBSD Mailing List References: <9e16ee69-3793-41f5-385f-71d87dedcf2c@cloudzeeland.nl> <20220307141454.91255883d98dd7b980e6fc22@sohara.org> From: Arthur Chance In-Reply-To: <20220307141454.91255883d98dd7b980e6fc22@sohara.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4KC0yP2V49z3J59 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of freebsd@qeng-ho.org designates 217.155.128.244 as permitted sender) smtp.mailfrom=freebsd@qeng-ho.org X-Spamd-Result: default: False [-2.08 / 15.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+ip4:217.155.128.240/29]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[qeng-ho.org]; NEURAL_SPAM_MEDIUM(0.22)[0.222]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MLMMJ_DEST(0.00)[freebsd-questions]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:13037, ipnet:217.155.0.0/16, country:GB]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On 07/03/2022 14:14, Steve O'Hara-Smith wrote: > On Mon, 7 Mar 2022 14:36:19 +0100 > Jos Chrispijn 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é.