Executes scripts parallelly based on their success


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executes scripts parallelly based on their success
# 1  
Old 02-06-2014
Executes scripts parallelly based on their success

Hi Team ,
I have one Master.sh file which call X,Y,Z scripts ,
but here X may call again some sub scripts X_sub1.sh , X_sub2.sh
Y calls Y_sub1.sh,Y_sub2.sh and similarly Z script also .

Now requirement is Both X and Y should execute parallel bcz X and Y are independent each other , once X and Y finishes successfully then only Z will start bcz Z script will depend on X and Y,

All these scripts are places in Master.sh file.

My code in Master.sh file

Code:
bash X.sh &
bash Y.sh 
if [$? -eq 0]
bash Z.sh
fi


Last edited by bartus11; 02-06-2014 at 06:06 AM.. Reason: Please use [code][/code] tags.
# 2  
Old 02-06-2014
What is bcz? ( Im maybe tired ( its my before last day of support shift...)
# 3  
Old 02-06-2014
Quote:
Originally Posted by vbe
What is bcz? ( Im maybe tired ( its my before last day of support shift...)
I bet 'bcz' is 'because' in l33t-speak
# 4  
Old 02-07-2014
Dear Team ,
Apologize for shortcuts , Here "bcz" means because .
Hope above description gives sufficient details about problem, let me brief it again ,

Master.sh file contains X,Y,Z scripts , X may call again some sub scripts X_sub1.sh , X_sub2.sh ,Y calls Y_sub1.sh,Y_sub2.sh and similarly Z script also .

now X and Y should execute parallel, once X and Y finishes successfully then only Z script should start,
I kept below logic in Master.sh file ,

Code:
bash X.sh & bash Y.sh if [$? -eq 0] bash Z.sh fi

Above logic is working but Z script starts execution though X and Y are still running,
Please help me to write logic?

---------- Post updated at 02:55 PM ---------- Previous update was at 02:54 PM ----------

bash X.sh & bash Y.sh if [$? -eq 0] bash Z.sh fi
# 5  
Old 02-07-2014
Its just a question of putting a flag, like touch X-success at end of execution if successful, then to check if both flages are there, execute next step and finally remove the flags...
# 6  
Old 02-07-2014
Start both scripts in background and use the wait command to wait until both are finished. Use vbe's suggestion to check for success (modfy X.sh and Y.sh to create a flagfile if they finished successful).
Code:
X.sh &
Y.sh &
wait
[ -f x.flagfile -a -f y.flagfile ] && Z.sh

This User Gave Thanks to cero For This Post:
# 7  
Old 02-07-2014
Try:
Code:
bash X.sh &
Xpid=$!
bash Y.sh && wait $Xpid && bash Z.sh

These 2 Users Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to optimize the loop to load parallelly

Hi, I'm trying to load the huge amount of records in the database. I did the successful load but it took more time to load as numbers are huge. Here what I have - 1. create a database table (t) with 2 columns- Not an issue 2. create a script to load huge amount of data - Here I would... (2 Replies)
Discussion started by: Mannu2525
2 Replies

2. Shell Programming and Scripting

To execute scripts parallelly

Hi I have set two set of scripts sets in a file which perform similar operations but with different script names for e.g.: 1st set of script1.txt: 1.sh 2.sh 3.sh 4.sh 2nd set of script2.txt: 1_1.sh 2_1.sh 3_3.sh 4_4.sh I want to execute these set of scripts parallelly in such... (16 Replies)
Discussion started by: rohit_shinez
16 Replies

3. Shell Programming and Scripting

Search patterns in multiple logs parallelly.

Hi All, I am starting a service which will redirect its out put into 2 logs say A and B. Now for succesful startup of the service i need to search pattern1 in log A and pattern2 in log B which are writen continuosly. Now my requirement is to find the patterns in the increasing logs A and B... (19 Replies)
Discussion started by: Girish19
19 Replies

4. Programming

Python Conditional Statements Based on Success of Last Command

In shell scripting, I can create a conditional statement based on the success or failure (exit status)of a command such as: pinger() { ping -c 2 $remote_host >/dev/null 2>&1 ping_stat=$? } pinger if ]; then echo "blahblahblah" exit 0 fi how is this done using Python using... (3 Replies)
Discussion started by: metallica1973
3 Replies

5. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

6. Shell Programming and Scripting

Running Multiple scripts based on file size.

Hi, I have created 3 shell scripts which has to run one by one first two shell scripts will create a .txt files...which are used by the third shell script.Now I want to create a master script and run all these in a single script. Please give a pseudo code on how to so the same. ... (4 Replies)
Discussion started by: gaur.deepti
4 Replies

7. UNIX for Dummies Questions & Answers

Scripts based on vi

since no one can give me mapping or scripts to make vi easier I'm thinking about writing some for it. But first I need some help (hopefully this one will be answered) 1) How do I execute scripts based on user action ex. user press ctrl+h I let him insert stuff and then making a search based... (6 Replies)
Discussion started by: Bonzay0
6 Replies

8. Shell Programming and Scripting

Time based Processing of the Scripts

Any one can tell me how can i execute the processes for every 10 min.Actually iam having 3 Processes for every 10 min i want to run these 3 Process,one process at every 10 min. If any of the process is busy i just want to execute the free one. first 10 min execute P1 next 10 min execute P2... (3 Replies)
Discussion started by: krk_555
3 Replies

9. Shell Programming and Scripting

Need a simple file based utilty for shell scripts

Hello, I'm wondering if you may know of a simple file based UNIX utility that can be used to store and retrieve values on a flat file, let's say i have a file called "kru", i'd like to be able to specify a request like: while(....) if ; then kru.fld2 = $rec_cnt kru.fld3 =... (4 Replies)
Discussion started by: bobk544
4 Replies

10. Shell Programming and Scripting

Running three scripts parallelly

Hi All, We have three shell script batch, which extract data from three different systems(oracle, db2, db2/400). By running each shell script batch, the data is extracted from respective systems. while the batch is running, job date, system_name, start_date and end_date will be inserted into... (1 Reply)
Discussion started by: anwarsait
1 Replies
Login or Register to Ask a Question