Run multiple procedures from shell script parallely


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run multiple procedures from shell script parallely
# 1  
Old 02-25-2015
Question Run multiple procedures from shell script parallely

Hi,
I need to write a Shell Script wherein i will connect to a DB2 Database and run multiple DB procedures. I know how to do in a way where procedures will be called one after the other, like when first procedure finishes, second will be executed.

But what i want is to run them at the same time like we execute background processes. Is there a way to achieve this.

Any help will be appreciated
# 2  
Old 02-25-2015
Yes.

Run background processes from your shell script.
# 3  
Old 02-25-2015
Hi,

I cannot place .sql files and run them in background. Below is my code
Code:
#! /bin/sh
. ~/.bash_profile
clear
db_user=$1
db_passwd=$2
db2 connect to RPTPRDD1 user $db_user using $db_passwd
#Use Multiple calls if needs to be executed for multiple input parameters.


db2 "Call PROC1"
db2 "Call PROC2"
db2 "Call PROC3"

#Close DB connection
db2 connect reset

I need these three procs to run in parallel, not one after the other.
# 4  
Old 02-26-2015
After started bg process, save child process process id (variable !).
Code:
db2 "Call PROC1" &
pid1=$!

db2 "Call PROC2" &
pid2=$!

db2 "Call PROC3" &
pid3=$!


# then only wait that every process has done
wait $pid1 # wait process to end af it already ended then continue to the next line
wait $pid2 # so no need to make any while waiting 
wait $pid3

# or wait every together with one wait, wait exit after every process has ended.
wait $pid1 $pid2 $pid3

This User Gave Thanks to kshji For This Post:
# 5  
Old 02-26-2015
Hi Kshji,

I tried this approach. Even though processes are created and i can see their PIDs. Still only one procedure is executing at a given time, the first one in sequence, followed by second and so on.
I believe only one procedure call is possible per DB Session.

Is there a way to make 3 seperate DB Sessions and run the procs one each in them.
# 6  
Old 02-26-2015
This does create three separate sessions, by running db2 3 independent times.

If they are waiting for each other, there may be database locking involved and the like.

Or perhaps they are getting 'frozen' by attempting to interact with the user. They must be completely noninteractive to go in the background like this.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 02-26-2015
To verify locking part, I ran the procedures in three seperate unix sessions. They ran perfectly. So it cant be locking.
You also mentioned frozen for interaction with user.
I also added nohup to the procedure call commands, still result is same.

When I check in database also, it shows only one procedure running from that user, others are not even started.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to run multiple jobs and it's dependent jobs

I have multiple jobs and each job dependent on other job. Each Job generates a log and If job completed successfully log file end's with JOB ENDED SUCCESSFULLY message and if it failed then it will end with JOB ENDED with FAILURE. I need an help how to start. Attaching the JOB dependency... (3 Replies)
Discussion started by: santoshkumarkal
3 Replies

2. Shell Programming and Scripting

How to run scripts parallely inside shell script?

Hi , I have 4 scripts example script1,script2,script3,script4 . I have to run script1,script2 and script3 parallely since this 3 scripts dont have dependencies . Once script1,script2 and script3 got completed successfully , I have to trigger script4. Can someone help me on this how to... (10 Replies)
Discussion started by: vinothsekark
10 Replies

3. Shell Programming and Scripting

Run different SQL on multiple DBs using SHELL script

Hi Experts, I have a list of Dbs.In that DBs i need to execute some sql scripts. each sql script is unique and it should run on particular DB only. For example. i have DBs like MDC20V,NDC20V,ODC20V and sql scripts like MD.sql,ND.sql,OD.sql.so MD.sql should run only in MDC20V and ND.sql should... (1 Reply)
Discussion started by: navsan420
1 Replies

4. UNIX for Advanced & Expert Users

How to process multiple files parallely

Hi, I have a requirement to process multiple files in a directory parallely.Consider the below scenario: In a directory there are three files file1,file2 and file3.When I use for loop each file will be executed in sequence but I want to process parallely. Any Help would be appreciated.... (1 Reply)
Discussion started by: liyakathali
1 Replies

5. Shell Programming and Scripting

How to run multiple instances of shell script in linux?

How we can run the multiple instances of the script? I need to run the script which I am calling from the below function.I can doit with cron but I don't want to put it in the cron.This cript dploy the build and here I want when the build stage then it should run with multilpe instances of... (6 Replies)
Discussion started by: anuragpgtgerman
6 Replies

6. Shell Programming and Scripting

run vi/vim encrypted shell script without decryption on multiple servers

Hello Everyone, How do we run vi/vim encrypted shell script without decryption on multiple servers. It is a simple bash script and vim -nx <filename> has been used to encrypt with desired password. Now I have few errors, the syntax is absolutely fine as I have run that script multiple times on... (0 Replies)
Discussion started by: lovesaikrishna
0 Replies

7. UNIX and Linux Applications

how to run more than two processes parallely

I would like to call a function called CIRCLE which is further beind called by other function but in a loop that CIRCLE fuction is being called. And this CIRCLE function starts another process which takes 3 hours to complete again, if i put that process in nohup &, I can go to the next command... (2 Replies)
Discussion started by: venugopalsmartb
2 Replies

8. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

Hello I am trying to run a python program using shell script, which takes a single argument from a file. This file has one entry per line : 1aaa 2bbb 3ccc 4ddd 5eee ... ... ... My shell script runs the program, only for the last entry : #!/bin/sh IFS=$'\n' for line in $(cat... (2 Replies)
Discussion started by: ad23
2 Replies

9. Shell Programming and Scripting

Multiple Threads/Tasks to run parallely using the shell script

Scenario: I have two PCs (named as A & B) which would send some traps to my third PC (named as C). In PC C, I have to write a shell script such that it should accept the datas from both the PC-A & B parallely. So my question is, is it possible to have two different child threads/tasks... (2 Replies)
Discussion started by: nthiruvenkatam
2 Replies

10. Shell Programming and Scripting

Run a script parallely with different arguments

Hi! I want to run a script in parallel with different arguments. eg. start script.sh argA script.sh argB script.sh argC end Can someone please tell how to achieve this. Thanks in advance. (4 Replies)
Discussion started by: dummyix
4 Replies
Login or Register to Ask a Question