0

I have 4 shell scripts dog.sh, bird.sh, cow.sh and fox.sh. Each of these files execute 4 wgets in parallel using xargs to fork a separate process. Now I want these scripts themselves to be executed in parallel. For some portability reason unknown to me I can't use GNU parallel. IS there a way I can do this with xargs or with any other tool.

Also can I also ask what could the portability reason be?

I'm a total newbie to shell scripting. Sorry if my question seems cryptic.

Thanks in advance guys.

6
  • Without knowing your platform, it is pretty much impossible to determine what the portability reason could be. Commented Jun 18, 2014 at 5:44
  • My machine is running ubuntu linux. I know that xargs works on the machine on which the shell script is going to run Commented Jun 18, 2014 at 5:45
  • @Suresh But what platform(s) is it to be run on? Without that, people attempting to answer your question will not be able to give solutions that will actually work on the target machine. Commented Jun 18, 2014 at 5:47
  • I don't know :(. I'm guessing it musbt some flavor of unix that doesn't suport more recent GNU stuff. Commented Jun 18, 2014 at 5:51
  • I, too, would like to know the portability reason: GNU Parallel is designed to be extremely portable; as long as you have Perl 5.8 or later you simply copy the file 'parallel' and off you go. oletange.blogspot.dk/2013/04/why-not-install-gnu-parallel.html Commented Jun 19, 2014 at 6:13

1 Answer 1

3

The easiest way to do this is to background all four of the scripts. You could wrap these with another script "run_parallel.sh" that looks like this:

./dog.sh &
./bird.sh &
./cow.sh &
./fox.sh &

The ampersand backgrounds the invoked process in a non-blocking fashion causing all 4 to be executed at the same time.

As an example, here's a script called "one_two_three.sh":

echo 'One'
sleep 1
echo 'Two'
sleep 1
echo 'Three'
sleep 1
echo 'Done'

and a wrapper "wrapper.sh":

./one_two_three.sh &
./one_two_three.sh &
./one_two_three.sh &
./one_two_three.sh &
echo 'Four running at once!'
Sign up to request clarification or add additional context in comments.

2 Comments

I will also leave an update in a bit as to whether it worked on the target machine
Worked on target as well :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.