Last active
August 13, 2023 01:23
-
-
Save pacohope/599bb66594ed197c2a3e2d8bfafe3e56 to your computer and use it in GitHub Desktop.
Creates a single script to invoke a random delay on FreeBSD during execution of periodic(8) jobs. Updates /etc/crontab too
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# make delay periodic | |
# Called interactively as non-root user who has permission to sudo(8) | |
# | |
# Invoke interactively this way: fetch -o - https://gist.githubusercontent.com/pacohope/599bb66594ed197c2a3e2d8bfafe3e56/raw/8853effe2a325abedfd95bdd02219238343ce966/make-periodic-delay.sh | sh | |
# then type sudo password once (if password is required) | |
# | |
# Inspired by this thread: | |
# https://forums.freebsd.org/threads/delay-or-stagger-running-of-periodic-scripts-randomly.69641/ | |
sudo mkdir -p /usr/local/etc/periodic/delay | |
cat - > /tmp/000-delay.sh <<EOF | |
#!/bin/sh | |
DELAY=\$(jot -r 1 0 3600) | |
sleep \$DELAY | |
EOF | |
sudo cp /tmp/000-delay.sh /usr/local/etc/periodic/delay | |
sudo chmod 755 /usr/local/etc/periodic/delay/000-delay.sh | |
sudo perl -pi -e 's,periodic *(.*ly)$,periodic delay $1,g' /etc/crontab | |
rm -f /tmp/000-delay.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment