| RANDSLEEP(1) | General Commands Manual | RANDSLEEP(1) |
randsleep —
Execute program after sleeping for a random time
randsleep |
time [command args ...] |
This manual documents randsleep version
0.0
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.
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.
#!/bin/shif [ -z "$RANDOM" ];
thenRANDOM=$(dd if=/dev/urandom count=1
2> /dev/null | cksum | cut -c"1-5")fisleep $(( RANDOM % 1800
))# actually do somethingWith randsleep:
#!/bin/shrandsleep 1800# actually do somethingOr (as crontab entry):
10 * * * * root randsleep 1800
/path/to/script with argumentsCopyright (C) 2011 Daniel Friesel ⟨derf@finalrewind.org⟩.
You just DO WHAT THE FUCK YOU WANT TO.
| July 6, 2011 | Debian |