views:

116

answers:

2

Hello, I would to give the user the feature to run the shell script in background.

My shell program instantiates a number of other shell scripts.

Here is a small code snippet of my script

./main.sh  # Main script

in main.sh 

I call preprocessing.sh
create_dir.sh
handle_file.sh
post_processing.sh
report_generation.sh

I would like to know if I have to initiate all the child script as well.. What is the syntax if i have to initiate all the scripts in background and at the end inform the user by displaying message in that test run is complete.

Thanks

Kiran

A: 

add "&" to the end of the commands

I call preprocessing.sh &
create_dir.sh &
...
David
Thanks for the quick response, But How do I inform the user at the end of the test run by a simple echo message.. ??
Kiran
+1  A: 

Start your processes in the background with & and then use bash's builtin wait command:

  wait [n ...] 
          Wait for each specified process and return its termination  sta‐ 
          tus.   Each  n  may be a process ID or a job specification; if a 
          job spec is given, all processes  in  that  job’s  pipeline  are 
          waited  for.  

A couple of example are available here. For instance:

# wait on 2 processes
sleep 10 &
sleep 10 &
wait %1 %2 && echo "Completed!"
Martin Wickman
Thanks a lot.. I will try this
Kiran
Thanks, This is what I was looking for..
Kiran
are you sure that this is what you're looking for?? based on your script names it would appear that the sub-scripts must run sequentially, not all together in parallel (which is what the solution you accepted proposes.)
vladr