From: Simon Ruderich Date: Thu, 26 Dec 2013 03:52:50 +0000 (+0100) Subject: Add rsleep script and use it in crontab.d/jobs. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=a1b28253ff5324d4b67a3a7bb113dac84e564e06;p=config%2Fdotfiles.git Add rsleep script and use it in crontab.d/jobs. --- diff --git a/bin/rsleep b/bin/rsleep new file mode 100755 index 0000000..120ec2e --- /dev/null +++ b/bin/rsleep @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +# Sleep randomly betwenn 0 and $ARGV[0] seconds. + +# Copyright (C) 2013 Simon Ruderich +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +use strict; +use warnings; + + +if (scalar @ARGV != 1) { + print STDERR "Usage: $0 \n"; + exit 1; +} + +srand; +sleep int rand $ARGV[0]; diff --git a/crontab.d/jobs b/crontab.d/jobs index 1e6c4d2..f898f22 100644 --- a/crontab.d/jobs +++ b/crontab.d/jobs @@ -21,17 +21,16 @@ # 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 +# `rsleep` (random sleep) is 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 * * * * 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 +17 * * * * rsleep 60; run-parts --report .crontab.d/jobs.hourly +25 6 * * * rsleep 1800; run-parts --report .crontab.d/jobs.daily +47 6 * * 7 rsleep 3600; run-parts --report .crontab.d/jobs.weekly +52 6 1 * * rsleep 3600; run-parts --report .crontab.d/jobs.monthly # Run on system startup. @reboot run-parts --report .crontab.d/jobs.reboot @@ -39,7 +38,7 @@ PATH=$HOME/bin:$HOME/.shell/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/u # Run every minute. * * * * * run-parts --report .crontab.d/jobs.minutely # Run every x hours. -31 */6 * * * RAND_SLEEP 600; run-parts --report .crontab.d/jobs.hourly6 -39 */8 * * * RAND_SLEEP 600; run-parts --report .crontab.d/jobs.hourly8 +31 */6 * * * rsleep 600; run-parts --report .crontab.d/jobs.hourly6 +39 */8 * * * rsleep 600; run-parts --report .crontab.d/jobs.hourly8 # vim: ft=crontab diff --git a/crontab.d/update.sh b/crontab.d/update.sh index fd4a9ae..2b174c1 100755 --- a/crontab.d/update.sh +++ b/crontab.d/update.sh @@ -77,7 +77,6 @@ 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