RANDSLEEP(1) General Commands Manual RANDSLEEP(1)
NAME
randsleepExecute program after sleeping for a random time
SYNOPSIS
randsleep time [command args ...]
VERSION
This manual documents randsleep version 0.0
DESCRIPTION
randsleep execs into command after sleeping for up to time seconds. It is intended for use in cronjobs and similar.
 
If command is not specified, randsleep will simply return after sleeping.
RATIONALE
When executing commands via cron, you can only select the point at which they're run in minute granularity. Also, you rarely know how many other commands may be started at the same point. To avoid load spikes by too many cronjobs running at the same time, it has become a rather widespread practice to sleep for a random amount of time (usually something between 0 and 30 minutes at most) before actually doing anything.
 
Since the snippets responsible for this may, especially if the shell does not support $RANDOM, become quite long, I decided to write this utility. It is an extremely simple C program with no additional dependencies, so using it should not be a problem.
EXAMPLE
#!/bin/sh
if [ -z "$RANDOM" ]; then
RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null |cksum |cut -c"1-5")
fi
sleep $(( RANDOM % 1800 ))
# actually do something
 
With randsleep:
#!/bin/sh
randsleep 1800
# actually do something
 
Or (as crontab entry):
10 * * * * root randsleep 1800 /path/to/script with arguments
AUTHOR
Copyright (C) 2011 Daniel Friesel ⟨derf@finalrewind.org⟩.
LICENSE
You just DO WHAT THE FUCK YOU WANT TO.