.Dd July 06, 2011 .Dt RANDSLEEP 1 .Os . . .Sh NAME . .Nm randsleep .Nd Execute program after sleeping for a random time . . .Sh SYNOPSIS . .Nm .Ar time .Op Ar command args ... . . .Sh VERSION . This manual documents .Nm version 0.0 . . .Sh DESCRIPTION . .Nm execs into .Ar command after sleeping for up to .Ar time seconds. It is intended for use in cronjobs and similar. . .Pp . If .Ar command is not specified, .Nm will simply return after sleeping. . . .Sh 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 .Pq usually something between 0 and 30 minutes at most before actually doing anything. . .Pp . Since the snippets responsible for this may, especially if the shell does not support .Ev $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. . . .Sh EXAMPLES . . .Ss CRONTAB ONE-LINER . .Dl */10 * * * * root sleep $(( RANDOM % 120 )); do_stuff with arguments . .Pp . With .Nm , this would look like: . .Dl */10 * * * * root randsleep 120 do_stuff with arguments . . .Ss CRONJOB SCRIPT . .Dl #!/bin/sh .Dl if [\& -z \&"$RANDOM\&" ]; then .Dl RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c\&"1-5\&") .Dl fi .Dl sleep $(( RANDOM % 1800 )) .Dl # actually do something . .Pp . With .Nm : . .Dl #!/bin/sh .Dl randsleep 1800 .Dl # actually do something . . .Sh AUTHOR . Copyright (C) 2011 Daniel Friesel .Aq derf@finalrewind.org . . . .Sh LICENSE . You just DO WHAT THE FUCK YOU WANT TO.