Fix mismatch in instructions for automatic updates in FreeBSD
The instructions include a randomized delay for the updates with RAND=$(jot -r 1 900). The instructions later mentions that it should yield anywhere from 0 to 900.
will trigger the packages updates process itself depending on the value set to the
$RANDvariable - it's configured to produce a sleep between 0 and 900 seconds (15 minutes) However, according to the man page forjotin version FreeBSD 13.3-RELEASE, the specified values are interpreted as:
- option: random
- repetitions:
1 - start:
900 - end: default: 100
- step / random seed: default: random for random option
As a test, I ran this in FreeBSD 15.0-RELEASE:
jot -r 10000 900 | while read n ; do [ 100 -ge $n ] && echo $n ; done
and the only numbers that show are 100, indicating that it will not yield 0 to 99 seconds.
The explanation for the 0 to 15 minutes is inconsistent with the command.
I suggest a change for the RAND value to be set like this: RAND=$(jot -r 1 0 900) (add an explict 0 as the start of the range).
Begin info not directly related to issue:
As an aside, the sleep command can be made more explicit by adding seconds:
sleep "${RAND}s"
but that is default anyways.
I came across this as I attempt to reduce the setup so that it's all within the cron job itself:
PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
BATCH=yes
IGNORE_OSVERSION=yes
0 0 * * * root sleep "$(jot -r 1 0 900)s" ; pkg update -q -f && pkg upgrade -q -U -y --fetch-only && HANDLE_RC_SCRIPTS=yes pkg upgrade -q -U -y
It drops the use of env, but I do not know enough if that's going to cause security issues. It may have been required for the independent script because it may be called interactively. This is air code; didn't test it long enough to find issues with it yet.