Running 3 shell script parallel in another shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running 3 shell script parallel in another shell script
# 1  
Old 01-21-2015
Running 3 shell script parallel in another shell script

Hi,

I'm trying to do teh below thing.

I have a single script which uses 3 different parameters to do 3 different work like belwo.

test1.sh par1 -- it shuts down an instance
test1.sh par2 -- it shuts down an instance
test1.sh par3 -- it shuts down an instance

Now I created a script test.sh where I'm calling the above one as below.

test1.sh par1 && test1.sh par2 && test1.sh par3

I think the above code will run the test1.sh with 3 different parameters in sequentially i.e. if first one completes then second in this way.

I want to run above three scripts in parallel not sequentially , so please suggest me how I can do this.

Thanks in advance.
# 2  
Old 01-21-2015
You could do:
Code:
script1 arg1 arg2 &
script2 arg1 arg2 arg3 &

Which will send the scripts to a subshell/background job, so you can enter new commands - this is almost 'paralell'.

OR

I'd have a ready solution for you, which got inspired by How to run scripts parallely inside shell script?.
A detailed description to be found in: [BASH] Script to manage background scripts (running, finished, exit code)

Which became part of TUI : https://www.unix.com/shell-programmin...k-scripts.html

Preview: https://raw.githubusercontent.com/sr...ts/tui-psm.jpg

However, it only execute scripts, without arguments.
So you would have to create for each script a script which calls the script with arguments.
Then pass those 'holding-scripts' to tui-psm.

Hope this helps
# 3  
Old 01-21-2015
Parallel execution

You could do this in test.sh

test1.sh par1 &
test1.sh par2 &
test1.sh par3 &

I don't know what you have in test1.sh but if it is a simple command to shutdown some process, you could call the command itself in a loop and background each.
# 4  
Old 01-21-2015
Hi,

Thanks for the reply.
So I understand if I run below it will run the 3 scripts in parallel.

test1.sh par1 &
test1.sh par2 &
test1.sh par3 &

Now I have 2 questions.

How UNIX will call test1.sh par2 & after test1.sh par1 &.
test1.sh par1 & we are running in backgroud , so after kicking this script shall it automatically kick test1.sh par2 & without considering the first one to fail or success?

SEA -->

Why we are calling wait call in your example?
wait $p1 && wait $p2 && wait $p3 - Is it when p1 completes it will start p2 ...

Request you to please explain this.

Thnaks in advance.
# 5  
Old 01-21-2015
Please use code tags as required by the forum rules.

We are not calling wait.
It executes the scripts in background, and 'wait' is used as intervall to check wether the script has started yet, is still running, or how it exited.

Change:
Code:
test1.sh par2 & after test1.sh par1 &

to:
Code:
(test1.sh par2 && test1 par1) &

To run the the par1 only if par2 ended successfully, if you want to run it anyway, use ; instead of &&.

hth

EDIT: test1.sh par2 && test1 par1 could be the content of a file passed to tui-psm.
# 6  
Old 01-21-2015
I don't understand what you want

Sorry I don't understand you. If you want to run them in parallel you cannot wait for one to succeed before launching the next...

Parallel
Code:
test1.sh par1 &
test1.sh par2 &
test1.sh par3 &

Sequential
Code:
test1.sh par1 
test1.sh par2 
test1.sh par3

Sequential only if previous succeeds
Code:
test1.sh par1 && test1.sh par2 && test1.sh par3

# 7  
Old 01-22-2015
Sure, if you let it only execute (set the limit to) one at a time.... it will do a sequence only / as well.

Just to be complete, if one tells the command the limit is 5, it will start t scripts at once in paralell.
And then check every few secs if one or more has ended.
So if 3 had ended, it can start another 3 at once.
If you set the limit to 1000, it could run a thousand scripst in paralell, but still would need to check every few secs, if some had ended and if there are remainings to start.

Its designed to work with more scripts, not just 3, but for some reason, 3 is always the question on the forum.

Also, its not (only) ment to run scripts in background, but also to let you know how they returned.

But guess/seems its an overkill for your needs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parallel for in a Script Shell

Hello, This is my Script which configure a list of nodes. ( 40 nodes, and the configuration 10 minutes) #! /bin/sh if then echo "USE: ./start.sh nodes else nb_lignes=`wc -l $1 | cut -d " " -f1` echo "$nb_lignes machines" for i in $(seq $nb_lignes) //instructions done fi My... (2 Replies)
Discussion started by: chercheur111
2 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

4. Shell Programming and Scripting

[Solved] Running a R script with in a shell script

Hi, I do have an R script named KO.R. Basically reads thousands of files, whose name has a pattern that differs at a portion of the file name, List.txt. Row_file1_mile.txt Row_file2_mile.txt Row_file3_mile.txt ... ... Row_file1000_mile.txt Below is a portion of my Rscript that reads... (4 Replies)
Discussion started by: Kanja
4 Replies

5. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

6. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

7. Shell Programming and Scripting

Parallel SQL sessions in shell script

i have 3 sqls , sql 1 and sql 2 shuld run in parallel , but sql 3 should run after completion f sql1 nd sql2, my code is as below, please suggest the changes sqlplus username1/password1@DB1 @sql >> log1 & sqlplus username2/password2@DB2 @sql2 >> log1 & how can i execute the... (7 Replies)
Discussion started by: only4satish
7 Replies

8. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

9. Shell Programming and Scripting

Help with executing parallel sessions for same shell script with different but fixed parameters

Hi Experts, There is a shell script that accepts positional parameter between 1-25 to execute case statement of script depending upon the parameter passed. Now I need to run all the 25 sessions parallely. In each option of case statement it is connecting with sqlplus and executing a select... (11 Replies)
Discussion started by: Opamps123
11 Replies

10. Shell Programming and Scripting

Running shell script in parallel

Hi, I am a shell script which takes input parameters and performs various functions. My concern is, if we call the same shell script with different parameter values from different sessions, will the results be inconsistent? Are there any precautions I need to take inorder to avoid conflicts... (1 Reply)
Discussion started by: jamjam10k
1 Replies
Login or Register to Ask a Question