Last active
March 6, 2021 06:42
-
-
Save kxalex/5584a6d364a0da74ff7e83fbf28c2111 to your computer and use it in GitHub Desktop.
Run cron job at random time
This file contains hidden or 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
# Run /your/script.sh at random time | |
04 */3 * * * sleep $((RANDOM\%90))m; /your/script.sh | |
# RANDOM versions: | |
# ${RANDOM:0:2}m | |
# $[RANDOM\%90]m | |
# | |
# No bash version: | |
# $(( $(od -N1 -tuC -An /dev/urandom) \% 90 ))m | |
# | |
# Note: You need to render modulus as '\%' above because cron (well, at least Linux 'vixie-cron') terminates the line when it encounters an unescaped '%'. | |
# Debugging cron | |
# * You should have `mailutils` installed | |
# * Use `mail` to check mails in your box from CRON | |
# * Output of the crontab jobs (including errors) is sent through email to the user the crontab file belongs to (unless redirected). | |
# * To see when it was ran: | |
# grep CRON /var/log/syslog | |
# | |
# `crontab -e` to edit crontab for current user | |
# `crontab -l` list jobs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment