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.
On Wed, May 15, 2013 at 11:44 AM, Matt matt.mailinglists@gmail.com 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.
Use your script to generate a random number [0] and pass that to the sleep command?
[0] http://islandlinux.org/howto/generate-random-numbers-bash-scripting
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. _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Something like
sleep $(($(date +%S)*3))
More random would be to use nanoseconds (see date manpage), but then you'd have to cook up an algorithm to test and toss out values (arguments to 'sleep') which you didn't want.
On 05/15/2013 11:44 AM 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. _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
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
On 2013-05-15 17:44, 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.
Wait randomized interval of 60 seconds and start
perl -e "sleep(int(rand(60)))" && (perl /scripts/my_script.pl)
On Wed, May 15, 2013 at 1:38 PM, Thomas Johansson thomasj@isy.liu.se wrote:
On 2013-05-15 17:44, Matt wrote:
When I run them all at once they bog the system and cause some of latency graphs on equipment being monitored to look poor.
Wait randomized interval of 60 seconds and start
perl -e "sleep(int(rand(60)))" && (perl /scripts/my_script.pl)
Also you can add a wait to the script after starting some number of background commands to wait until they have all completed before you start another batch. But, rather than using so many home-grown scripts, maybe you should look at OpenNMS, cacti, etc. for monitoring frameworks to manage it all for you.
-- Les Mikesell lesmikesell@gmail.com
Am 15.05.2013 um 17:44 schrieb Matt matt.mailinglists@gmail.com:
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