[CentOS] Shell Scripting Random Delay

Wed May 15 17:59:25 UTC 2013
m.roth at 5-cent.us <m.roth at 5-cent.us>

Matt wrote:
> I have a shell script that's run every 5 minutes I use to call many
> other shell scripts.  Is there a way to wait a random number of
> seconds before executing each line?  Something like this.
>
> wait_random 10 - 180 (perl /scripts/my_script.pl) &
> wait_random 10 - 180 (perl /scripts/my_script5.pl) &
> wait_random 10 - 180 (perl /scripts/my_script7.pl) &
>
> I have many entries in this file and I background them all because
> most must poll network devices which can take time.  None should take
> over 2 minutes though.
>
> When I run them all at once they bog the system and cause some of
> latency graphs on equipment being monitored to look poor.

There's a better answer: do some testing to find out just how many you can
do at a time without the network bogging down, then
for ( $list <space separated line of file with devices> ) {
    my_script.pl $list
}

With the datafile being something like
#fast device responders
dev1 dev2 dev3 dev4
dev5 dev6 dev7 dev8
#slow device responders
sdev1 sdev2
sdev3 sdev4

And make your script do all of the first line, then wait for responses.

       mark