Register
It is currently Sun Apr 22, 2018 9:52 pm

need a script that will run three other scripts at a time


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Fri Oct 06, 2017 12:30 pm   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 38
So, I have a script that needs to call/ run several other scripts in a directory, but only three at a time.

So, let's say in /dir/scripts/ I have the following files:

update-abc1.sh
update-abc2.sh
update-abc3.sh
update-abc4.sh
...
update-abc9.sh

I need to run update the first three, then after they complete, the next three will kick off and run, until all of them are done. the 9 files is not static, it could be 20 files at different times, depending on some other stuff that I got going on.

any help would be greatly appreciated. :)


Top
 Profile  
 PostPosted: Sat Oct 07, 2017 7:37 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
If there is no communication between the "master" script and the update scripts, you have to rely on the existence of the processes, which means to rely on the persistence of $PID.
Hence there is a chance of failing on high load machines.

If this doesn't matter, there are lots of solutions.
But it is not clear what you're really after.
If you run 'em just serially, your condition is met by just running 'em serially.

Bash got provides an internal command wait. Read man wait.

Code:
# run all commands in background
command1 &
pid1=$!   # save PID

command2 &
pid2=$!

wait $pid1 $pid2
doSomethingMore


Top
 Profile  
 PostPosted: Tue Oct 10, 2017 8:39 am   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 38
The basis behind this is pushing certain patches to servers (that aren't on the Internet). Basically, I have everything set up, each host has it's own script that will do patches depending on what type of activities that server is doing (i.e. DB, etc). I don't want to kick off a dozen patches at once, hence the reason I was trying to do them three at a time. When those three are finished, the next three will start, until they are all complete.


Top
 Profile  
 PostPosted: Tue Oct 10, 2017 5:21 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
Then you should include into the patch scripts some kind of feedback mechanism to inform the script about remote stati.
The basic kind of syncing stays the same.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP