Running scripts in background


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running scripts in background
# 1  
Old 01-23-2015
Running scripts in background

Hi, below is my master script wihch inturn runs 2 scripts in background
Code:
#master_script.sh
./subscript1.sh &
./subscript2.sh &

executed the master_script.sh from unix command prompt
Code:
$ ./master_script.sh

it is executing the subscripts and they are completing fine, however master_script.sh is not coming out (means it is not coming back to command prompt ($)) , i have to press Ctrl+C to come out.

changed master script as below,
Code:
#master_script.sh
./subscript1.sh 2>/dev/null &
./subscript2.sh 2>/dev/null &

Now it is getting redirected to command prompt. My question, is there any way we can write the subscript1, 2 outputs to files (output similar to set -x ) and comes out
# 2  
Old 01-23-2015
Either:
Code:
./master_script.sh > /path/to/file

OR
Code:
./subscript{1,2}.sh 2>/dev/null 1>/path/to/file &

should do the trick.

hth
These 2 Users Gave Thanks to sea For This Post:
# 3  
Old 01-23-2015
ITYM
Code:
./subscript1.sh 2>/dev/null 1>/path/to/file1 &
./subscript2.sh 2>/dev/null 1>/path/to/file2 &

I.e. two commands and separate output files.
It is possible to merge the stderr to the same file:
Code:
./subscript1.sh 1>/path/to/file1 2>&1 &
./subscript2.sh 1>/path/to/file2 2>&1 &

NB here the order of redirections matters: first redirect stdout to the file, then redirect stderr to the stdout descriptor.
(While ./subscript1.sh 2>/path/to/file1 1>&2 & would effectively do the same thing.)
This User Gave Thanks to MadeInGermany 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

Run scripts in background one by one

Hello all, Can someone help with one script? I have as example 3 scripts 1.sh sleep 60 & sleep 60 & sleep 10 & sleep 80 & sleep 60 & 2.sh sleep 40 & sleep 5 & sleep 10 & sleep 70 & sleep 60 & 3.sh (2 Replies)
Discussion started by: vikus
2 Replies

2. Shell Programming and Scripting

How to run scripts sequentially in background?

Hi , I have prepared the following shell script to run the hqls in background. These scripts are running Parallel but I want to run the hqls sequentially in background. cat >cc_script.ksh nohup hive -hiveconf rrdt=2016-06-12 -f /home/files/cust1.hql > home/log/cust1.log 2>&1 & nohup hive... (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

3. Shell Programming and Scripting

Problems running scripts in the background

Hi Could someone offer some help on this problem I've got with running a background process. As part of a script that does a stop/start/status for a piece of software called SAS, the following extract is from part of the start step. My issue is that when the script is run, the control... (0 Replies)
Discussion started by: GavP
0 Replies

4. 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

5. Shell Programming and Scripting

Running in background

Hello, I was trying to make some processes to run at background and went to a problem. First I tried just to loop in one line something like this: for i in {1..10}; do echo 'hello world' &; done; but it pops a syntax error, so I tried several ways to fix it but wasn't able to understand... (2 Replies)
Discussion started by: Rash
2 Replies

6. Shell Programming and Scripting

background scripts run-help

Looking for a logic where say i have a script called parent_script which is used to call other 4 to 5 child scripts in background as.. cat parent_script # containing 65 lines 1 2 .. 35 while read child_script 36 do 37 ./child_script_name& 38 done< ${SCRIPT_LISTS} 39 40 # Need to have... (2 Replies)
Discussion started by: michaelrozar17
2 Replies

7. Shell Programming and Scripting

Simutaneous scripts within a background task

Hi, I have a script that polls a directory using inotifywait. This script is always running in the background. Within that script, I have 2 commands that need to run simultaneously. When those scripts are finished, I have to fire off a 3rd. The problem is, the 3rd script is never being... (0 Replies)
Discussion started by: gseyforth
0 Replies

8. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

9. Shell Programming and Scripting

running in background

i have a script called server.sh. how to run this script in backgroung using nohup command (5 Replies)
Discussion started by: ali560045
5 Replies

10. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: Omkumar
4 Replies
Login or Register to Ask a Question