http://undeadly.org/cgi?action=article;sid=20230507122935 Front page [ ] [Search site] OpenBSD Journal Home Archives About Submit Story Create Account Login cron(8) now supports random ranges with steps Contributed by rueda on 2023-05-07 from the not-a-random-walk dept. Thanks to the following commit by Todd Miller (millert@), cron(8) now supports random values in a range with a step value (i.e. "~/ " in crontab(5) entries): CVSROOT: /cvs Module name: src Changes by: millert@cvs.openbsd.org 2023/05/06 17:06:27 Modified files: usr.sbin/cron : crontab.5 entry.c macros.h Log message: Support random offsets when using ranges with a step value in cron. This extends the random range syntax to support step values. Instead of choosing a random number between the high and low values, the field is treated as a range with a random offset less than the step value. This can be used to avoid thundering herd problems where multiple machines contact a server all at the same time via cron jobs. The syntax is similar to the existing range/step syntax but uses a random range. For example, instead of "0-59/10" in the minutes field, "0~59/10" can be used to run a command every 10 minutes where the first command starts at a random offset in the range [0,9]. The high and low numbers are optional, "~/10" can be used instead. Requested by job@, OK phessler@ Reply --------------------------------------------------------------------- Comments 1. By John McCue (jmcunx) jmcq66@comcast.net on 2023-05-07 14:39 Nice, I really like all the changes happening with cron If I understand the usage, if I specify "~/20" in the minutes field, will the job start somewhere between minutes 0-19 ? Reply Comments 1. By grey (grey) on 2023-05-07 17:26 http://www.artkiver.com That would be my guess? I'm not sure and haven't tested personally yet so others please feel free to correct me. This seems similar to -j (jitter) in FreeBSD's cron (which some have referred to as "Vixie cron" but I think Paul Vixie (cited in the manpage of OpenBSD as well) would probably need to shed more light on the branching of that feature without referring to older source code changes in another project, which I guess I'll leave as "an exercise for the reader" (though honestly now I am curious where/when such feature was introduced). Reply 2. By Ampie Niemand (Ampie) ampien@gmail.com on 2023-05-08 07:37 Hi, I believe ~/20 means every 20 minutes randomly within the hour. Reply Comments 1. By John McCue (jmcunx) jmcq66@comcast.net on 2023-05-08 17:52 That makes sense so if I have ~/20, it could execute as: r1: 17 mins (random time picked) r2: Then between 37 -- 57 or probably between 20 -- 40 minutes r3: r2 +20 before the end of the hour or somewhere between 40 -- 59 I will play with it once it hits cron to be sure Reply Latest Articles * Sun, May 07 + 12:29 cron(8) now supports random ranges with steps (4) * Fri, May 05 + 05:42 OpenBGPD 8.0 released (0) * Wed, May 03 + 16:29 rpki-client 8.4 released (0) * Sun, Apr 30 + 10:27 Game of Trees 0.88 released! (2) + 05:13 VM owners can now override the boot kernel (0) + 05:12 vmd(8) moves to a multi-process model (1) * Fri, Apr 21 + 12:42 viogpu(4), a VirtIO GPU driver, added to -current (2) + 06:49 Game of Trees 0.87 released (0) * Mon, Apr 17 + 07:49 malloc leak detection available in -current (1) Credits Copyright (c) 2004-2008 Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to April 2nd 2004 as well as images and HTML templates were copied from the fabulous original deadly.org with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]