Execute scripts in Parallel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute scripts in Parallel
# 1  
Old 11-28-2011
Execute scripts in Parallel

Hi
I want to execute few scripts in Parallel. There is a Master Script (MS.ksh) which will call internally all the scripts we need to run in Parallel. Say there are three set of scripts :

ABC_1.ksh --> ABC_2.ksh --> ABC_3.ksh (execute ABC_2 when ABC_1 is successful ; Execute ABC_3 only when ABC_2 is successful)

XYZ_1.ksh --> XYZ_2.ksh --> XYZ_3.ksh(execute XYZ_2 when XYZ_1 is successful ; Execute XYZ_3 only when XYZ_2 is successful)

When I call MS.ksh then it should parallely execute ABC_1.ksh (& subsequent scripts) & XYZ_1.ksh(& subsequent scripts)

Thanks in advance.
# 2  
Old 11-28-2011
Code:
 
ABC_1.ksh && ABC_2.ksh && ABC_3.ksh

# 3  
Old 11-28-2011
Hi

Does that command execute ABC_1.ksh first & only if it is successfully executed it will execute ABC_2.ksh & then ABC_3.ksh or all three scripts in parallel ?

Thanks in advance
# 4  
Old 11-28-2011
yes...

for a test

just execute the below commands


Code:
 
echo "I am success" && echo "2nd success" && echo "3rd success"

# 5  
Old 11-28-2011
Use fork

Code:
#! /usr/bin/perl -w
use strict;

if (fork) {
    <execute one set of scripts>
}
else {
    <execute another set of scripts>
}

# 6  
Old 11-28-2011
If you want to execute the ABC batch concurrently with the XYZ batch you will need to background both processes (nohup .... &). Neither script must ask questions because it will lose terminal context when in background.

These example scripts assume that all the scripts are executable and can be found through $PATH.

Code:
#MS.ksh
nohup ABC_batch.ksh > ABC_batch.log &
nohup XYZ_batch.ksh > XYZ_batch.log &

#ABC_batch.ksh
ABC_1.ksh && ABC_2.ksh && ABC_3.ksh

#XYZ_batch.ksh
XYZ_1.ksh && XYZ_2.ksh && XYZ_3.ksh

# 7  
Old 11-28-2011
Quote:
Originally Posted by dashing201
Hi


ABC_1.ksh --> ABC_2.ksh --> ABC_3.ksh (execute ABC_2 when ABC_1 is successful ; Execute ABC_3 only when ABC_2 is successful)

Thanks in advance.
I would use this :

/absolute_path/ABC_1.ksh
if [ $? -eq 0 ]; then
/absolute_path/ABC_2.ksh
if [ $? -eq 0 ]; then
/absolute_path/ABC_3.ksh
else
echo "only ABC_1.ksh and ABC_2.ksh were executed"
fi
else
echo "only ABC_1.ksh was executed"
fi

Considering that $? stores the value of the exit status of the last executed script (command) and each script is executed UNsuccesfully when its exit status is other than 0 .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parallel bash scripts

Need some help to replace bash script with parallel to speed up job on multiple files (400files.list is the file contains the absolute path to those 400 files). The bash script is to run the same program over the files repetitively. My bash_script.sh is: for sample in `cat 400files.list`; do... (3 Replies)
Discussion started by: yifangt
3 Replies

2. AIX

Need ./ to execute scripts

Hi, I am really sorry for this question but still i am confused. I have shell script called sample.sh I can execute only with the combination of ./sample.sh Is ./ really necessary ? Is it something related with $HOME or $PATH variable. Why and How can i resolve this case ? ... (2 Replies)
Discussion started by: Nandy
2 Replies

3. Shell Programming and Scripting

[Solved] Running scripts in parallel

i have script A and script B, both scripts have to run in parallel, my requirement is script A create table temp1, post creating it will run fr 4 hrs , script B has to start 0nly after creation of table temp1 ( which is done by script A) , again script B will run for 5 hrs if i run sequencially... (7 Replies)
Discussion started by: only4satish
7 Replies

4. Shell Programming and Scripting

[Solved] Running scripts in parallel that issue prompt

Hi all - I am totally stuck here :wall I have been asked to write a shell script that does a few little things and then reads from a config file and kicks off an instance of another script, say scriptB.ksh for each line in the config file. These should all be run in parallel. This is all fine but... (2 Replies)
Discussion started by: sjmolloy
2 Replies

5. Shell Programming and Scripting

Find and execute shell scripts in multiple sub directories in parallel

I have one parent directory and within that parent directory there are several other sub-directories and within those sub-directories there are several other "large number" of sub-directories. All the sub directories have a shell script in them with a common file name execute_command.sh I want... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

6. Shell Programming and Scripting

need to have a cronjob which will execute certain scripts every hr

Hi My question needs two answers how to write scripts to update a table in oracle db based on the result of the number of record counts for example i need to execute the following script every hour awk '{sum++;}END{for(i in sum) {print i, sum}}' filename here everyhour the... (3 Replies)
Discussion started by: aemunathan
3 Replies

7. Shell Programming and Scripting

Executing scripts in Parallel

Hi All, I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2. Could you please suggest an approach of acheiving this... Thanks in advance (2 Replies)
Discussion started by: itsme_maverick
2 Replies

8. Shell Programming and Scripting

Running scripts in parallel

Hi, Iam having the scripts as follows. i jus want to run those in parallel. main aim is to minimise the time for overall execution of the script. now out.txt is having 1 lac records. script1(split.sh) split -1000 out.txt splitout ls -A splitout* > filelist.txt cat filelist.txt... (6 Replies)
Discussion started by: nivas
6 Replies

9. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

10. Shell Programming and Scripting

Execute commands parallel in a for loop ?

Hi, please can someone point me in the right direction with a shell scripting problem. I want to execute a command in a for loop and the command should be started not one-by-one meaning the for loop is waiting for the exit code , it should be started in parallel. I have a plain text file... (3 Replies)
Discussion started by: networkfre@k
3 Replies
Login or Register to Ask a Question