Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run multiple ruby files in conjunction in a shell script?

Tags:

shell

ruby

I have a .sh file that looks like the following:

ruby one.rb
ruby two.rb
ruby three.rb
ruby four.rb
ruby five.rb
ruby six.rb
ruby seven.rb
ruby eight.rb

What this does is run the ruby files one by one. How would I go about launching the first four in conjunction and as soon as the first four are done grab the next set. Not sure how to approach this, any advice is appreciated. I want to avoid using rake for now and continue using shell.

like image 412
Josh Avatar asked Dec 06 '22 07:12

Josh


2 Answers

Have you tried using & and wait?

ruby one.rb &
ruby two.rb &
ruby three.rb &
ruby four.rb &
wait
ruby five.rb &
ruby six.rb &
ruby seven.rb &
ruby eight.rb &

http://tldp.org/LDP/abs/html/subshells.html

like image 91
Denis de Bernardy Avatar answered Dec 08 '22 21:12

Denis de Bernardy


Create a text file which looks like:

 one.rb
 two.rb
 three.rb

...and so on. Call it "jobs" or whatever you want. Then, assuming you are running Ubuntu or a similar system:

 sudo apt-get install parallel
 parallel ruby < jobs

Information on the parallel command is available here: http://www.gnu.org/software/parallel/

like image 35
Alex D Avatar answered Dec 08 '22 19:12

Alex D