exit status of Invoking two or more scripts in background


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting exit status of Invoking two or more scripts in background
# 1  
Old 03-31-2005
exit status of Invoking two or more scripts in background

I have a sript which is going to trigger other 3 scripts in background simultaneously

for eg:

Main Script:(main.sh)
-----------
sh a.sh &
sh b.sh &
sh c.sh &

How to catch the exit status and store it in a variable for all those three scripts in main script. Is there any other way of triggering the scripts simulataneously in background.

Thanks in advance for your answers.

-Om
# 2  
Old 03-31-2005
You can use log files ( output mode or error mode ) for redirecting exit code. For example,

#!/bin/sh
#a.sh
...
echo "1"
exit 1

..
echo "0"
exit 0
##

Execute this as,
sh a.sh 1>/tmp/ash.log 2>/dev/null &

It will do the trick.
# 3  
Old 03-31-2005
Hi Muthukumar,

Thanks for your help, but where is the exit status.

-Om

Last edited by Omkumar; 03-31-2005 at 07:49 AM..
# 4  
Old 03-31-2005
What about something like...
Code:
#!/bin/ksh
./a.sh &
pid_a=$!
./b.sh &
pid_b=$!
./c.sh &
pid_c=$!
wait $pid_a
echo "a.sh returned $?"
wait $pid_b
echo "b.sh returned $?"
wait $pid_c
echo "c.sh returned $?"

Cheers
ZB
# 5  
Old 03-31-2005
Vow!!!!, what a script. That worked.

Thanks again.

-Om
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[BASH] Script to manage background scripts (running, finished, exit code)

Heyas, Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p The last point for motivation was... (17 Replies)
Discussion started by: sea
17 Replies

2. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

3. Shell Programming and Scripting

Exit Shell Script with background job

Hi all, I am trying to exit a shell script (c shell) while invoking a job (service) that must run in the background: ...... /mydir/runservice & exit ...... There are downstream jobs and scripts that need to be run, but they all 'wait' for the script to exit. The script 'hangs' and... (3 Replies)
Discussion started by: CKT_newbie88
3 Replies

4. Shell Programming and Scripting

Capturing the exit status of the script running in background

Hi All, I have a scenario where I am executing some child shell scripts in background (using &)through a master parent script. Is there a way I can capture the exit status of each individual child script after the execution is completed. (2 Replies)
Discussion started by: paragkalra
2 Replies

5. Shell Programming and Scripting

check exit status of bg scripts

HI All, I am running one shell script, in that script i am calling 4 scripts in the background. abc.ksh & efg.ksh & xky.ksh & mno.ksh & please let me know, how could i find the success and failure of each script. i Cannot use $?, because i want to run all the scripts in parellel. ... (2 Replies)
Discussion started by: javeed7
2 Replies

6. Shell Programming and Scripting

Invoking 2 scripts in 1 command

HI, I have 2 scripts main.sh and sub.sh, I want to invoke both these scripts in 1 unix command.. Something like... csh -f main.sh(sub.sh TIBCO) sub.sh returns a value as .., by taking this value main.sh prints a text. Can anyone help me to build this command Below are the scripts ////sub.sh... (3 Replies)
Discussion started by: bce_groups
3 Replies

7. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

8. Shell Programming and Scripting

background jobs exit status and limit the number of jobs to run

i need to execute 5 jobs at a time in background and need to get the exit status of all the jobs i wrote small script below , i'm not sure this is right way to do it.any ideas please help. $cat run_job.ksh #!/usr/bin/ksh #################################### typeset -u SCHEMA_NAME=$1 ... (1 Reply)
Discussion started by: GrepMe
1 Replies

9. Shell Programming and Scripting

Issues with exit after running jobs in background

I have the following sample script to run a script the jobs with the same priority(in this case field3) in parallel; wait for the jobs to finish and run the next set of jobs in parallel.When all the lines are read exit the script. I have the following script which is doing evrything I want... (1 Reply)
Discussion started by: hyennah
1 Replies

10. Shell Programming and Scripting

retrieving exit status from background processes

Hi, I need to retrieve the exit status of 4 moves running as background processes. The wait command will not work since it can only give me the exit status of the last of the background processes. Here's a sample of what I need !#/bin/ksh mv /dir1/subdir1/*.Z /dir6/subdir6/ & mv... (2 Replies)
Discussion started by: MG537
2 Replies
Login or Register to Ask a Question