Run scripts in background one by one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run scripts in background one by one
# 1  
Old 01-04-2017
Run scripts in background one by one

Hello all,
Can someone help with one script?

I have as example 3 scripts
1.sh
Code:
sleep 60 &
sleep 60 &
sleep 10 &
sleep 80 &
sleep 60 &

2.sh
Code:
sleep 40 &
sleep 5 &
sleep 10 &
sleep 70 &
sleep 60 &

3.sh
Code:
sleep 40 &
sleep 5  &
sleep 10 &
sleep 70 &
sleep 60 &

Now I need script to run all those scripts one by one (not at the same time).
As we have "&" in each line script will finish and command will go in background.

Code:
while sleep 1 ; do
ps -ef | grep -q sleep
if [ $? != 0 ]
then
echo "no jobs let's run another script"
...(some part of script to take first 1.sh when is done take 2.sh etc...)
fi
done

# 2  
Old 01-04-2017
Those three scripts need wait statements at the end (as a last statement)
Code:
wait

Then you can just do something like this in the main script:
Code:
for i in 1 2 3 
do
  "./$i.sh"
done

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-04-2017
If you need to run them one by one, why are they in the background?

Script1 should be
Code:
sleep 60
sleep 60
sleep 10
sleep 80
sleep 60

and if you want to background it, do ./script1.sh &

Or alternatively you could do

Code:
(
        sleep 60
        sleep 60
        sleep 10
        sleep 80
        sleep 60
         ) &

disown # Only required in certain shells

Either way the solution is the same - put the shell in the background, not the applications. This allows the shell to remain in control of them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

Running scripts in background

Hi, below is my master script wihch inturn runs 2 scripts in background #master_script.sh ./subscript1.sh & ./subscript2.sh & executed the master_script.sh from unix command prompt $ ./master_script.sh it is executing the subscripts and they are completing fine, however master_script.sh is... (2 Replies)
Discussion started by: JSKOBS
2 Replies

4. UNIX for Dummies Questions & Answers

Scripts can be run manually but couldn't run with cronjobs

I am from MQ/MB technology. My requirement is to display the queue manger and broker status on daily basis. If I manually run the script, it works fine and displays output. But when I have scheduled the same using cronjobs it shows only the queue manger status and not the broker status. Can... (3 Replies)
Discussion started by: Anusha M
3 Replies

5. Shell Programming and Scripting

Run wineconsole in background

Hello everybody, I'm making a script for running a .bat process on wineconsole, but I want that wineconsole doesn't show up when I call it from the script. The script is named "reset" and it looks like this: When I execute it, it will show up the wineconsole window on top, and that is... (3 Replies)
Discussion started by: taurokpo
3 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. UNIX for Dummies Questions & Answers

can we run ssh2 in background

Hi, I was trying to run ssh2 command in background... but i got follwoing error message saying that process has been stopped.. + Stopped(SIGTTOU) Anyone have any idea about this??? Appreciated your help.. (3 Replies)
Discussion started by: pvamsikr
3 Replies

9. Shell Programming and Scripting

run a shell in the background

How can I run a shell in the background? cat test.sh #!/bin/sh sleep 600 Thank u very much indeed! (2 Replies)
Discussion started by: GCTEII
2 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