On Mon, 28 Jan 2013 22:45:31 -0800 Dennis Peterson articulated: > Bill Landry's unofficial sigs script does it right by using a random > function as an offset from cron time to actually initial a sig > download. For those of us with a couple dozen or more systems this is > a mirror-friendly way of not getting into lockstep with any > fixed-offset scheme. Here is the code segment from Bill's script and > I recommend something like it. > > if [ -n "$RANDOM" ] > then > sleep_time=$(($RANDOM * $(($max_sleep_time - > $min_sleep_time)) / 32767 + $min_sleep_time)) > else > sleep_time=0 > while [ "$sleep_time" -lt "$min_sleep_time" -o > "$sleep_time" -gt "$max_sleep_time" ] ; do > sleep_time=`head -1 /dev/urandom | cksum | awk '{print > $2}'` done > fi > > A bit of precision overkill given there are only 3600 seconds in an > hour, but it works. I use sleep $[ RANDOM % 900 ] and I have no idea > nor care when the signature download actually begins, but every > machine's crontab starts at the same time. The important thing to > remember here is there is a finite amount of time required to dl all > the sigs so regardless of the start time there will be overlap with > other clients just because there are more clients than there are > seconds in an hour.
I use a much simpler function: function get_files () { # This is the "snooze" test. It will delay the start of a download session # between 0 and 546 seconds (Roughly 9 minutes). It will only work when the # script is run via CRON. The variable $REST activates this function. # See if the variable 'REST' has been set or if forcing it from command line # And if we are running via CRON if [ ${REST} -gt 0 -a ! -t 0 ]; then # Use the BASH RANDOM function to generate a random number between 0 & 32767 RESTING=$((RANDOM/60)) sleep ${RESTING} fi ... } I never saw the benefit of expanding the time span, although it could be done easily enough. -- Jerry ♔ Disclaimer: off-list followups get on-list replies or get ignored. Please do not ignore the Reply-To header. __________________________________________________________________ _______________________________________________ Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net http://www.clamav.net/support/ml