Re: Shell Scripting Random Delay

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Am 15.05.2013 um 17:44 schrieb Matt <matt.mailinglists@xxxxxxxxx>:
> 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.


for bash scripts:

MOD="45"
sleep "$[($RANDOM % $MOD)]"

# RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated.
# sleep will wait something beetween 0 and 45 seconds 

--
LF

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux