From: Simon Ruderich Date: Sun, 18 Aug 2013 14:27:13 +0000 (+0200) Subject: crontab.d/jobs: Random sleep before running a command. X-Git-Url: https://ruderich.org/simon/gitweb/?p=config%2Fdotfiles.git;a=commitdiff_plain;h=556fcce13fb08df53b84f2878fdff27464aacf6b crontab.d/jobs: Random sleep before running a command. --- diff --git a/crontab.d/jobs b/crontab.d/jobs index fb83d9a..8f575fc 100644 --- a/crontab.d/jobs +++ b/crontab.d/jobs @@ -21,15 +21,18 @@ # Include user's binaries in PATH. Expanding $HOME doesn't work with cron, # `update.sh` handles that! PATH=$HOME/bin:$HOME/.shell/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games +# "RAND_SLEEP X" is also expanded by `update.sh` to a command which sleeps +# randomly between 0 and X seconds. Used to reduce concurrent commands if this +# crontab file is used by multiple users. # Taken from Debian's /etc/crontab from cron package 3.0pl1-124 and modified. # Thanks. -17 * * * * run-parts --report .crontab.d/jobs.hourly -25 6 * * * run-parts --report .crontab.d/jobs.daily -47 6 * * 7 run-parts --report .crontab.d/jobs.weekly -52 6 1 * * run-parts --report .crontab.d/jobs.monthly +17 * * * * RAND_SLEEP 60; run-parts --report .crontab.d/jobs.hourly +25 6 * * * RAND_SLEEP 1800; run-parts --report .crontab.d/jobs.daily +47 6 * * 7 RAND_SLEEP 3600; run-parts --report .crontab.d/jobs.weekly +52 6 1 * * RAND_SLEEP 3600; run-parts --report .crontab.d/jobs.monthly # Run every x hours. -31 */6 * * * run-parts --report .crontab.d/jobs.hourly6 -39 */8 * * * run-parts --report .crontab.d/jobs.hourly8 +31 */6 * * * RAND_SLEEP 600; run-parts --report .crontab.d/jobs.hourly6 +39 */8 * * * RAND_SLEEP 600; run-parts --report .crontab.d/jobs.hourly8 diff --git a/crontab.d/update.sh b/crontab.d/update.sh index 062c34e..173142e 100755 --- a/crontab.d/update.sh +++ b/crontab.d/update.sh @@ -78,6 +78,7 @@ for file in "$DIRECTORY"/crontab.*; do -e "/^# Copyright (C) [0-9][0-9]* / d" \ | cat --squeeze-blank \ | sed "/^PATH/ s:\$HOME:$HOME:g" \ + | sed 's/RAND_SLEEP \([0-9]*\)/sleep `perl -e "srand; print int rand \1;"`/' \ >> "$CRONTAB" done