]> ruderich.org/simon Gitweb - config/dotfiles.git/commitdiff
crontab.d/jobs: Random sleep before running a command.
authorSimon Ruderich <simon@ruderich.org>
Sun, 18 Aug 2013 14:27:13 +0000 (16:27 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 18 Aug 2013 14:27:13 +0000 (16:27 +0200)
crontab.d/jobs
crontab.d/update.sh

index fb83d9a467d0ca3b5376f7c094c4b70c0a553126..8f575fcc85b57d1b32459f8bca21e366c2f867bd 100644 (file)
 # 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
index 062c34eefb59b393513b18ffa3b7830c7fd68c59..173142ec214db7ddb29eed6ec690704ced1a97ed 100755 (executable)
@@ -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