run bunch of commands and wait
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4
shell-script
add a comment |Â
up vote
0
down vote
favorite
I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4
shell-script
4
Look into using the wait command.
â Raman Sailopal
Jan 22 at 8:57
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4
shell-script
I want to run bunch of commands simultaneously and when all of them finished, run another bunch of commands.some thing like this
command1 & command2
echo "command 1 and 2 finished"
command 3 & command 4
shell-script
asked Jan 22 at 8:52
Ebrahim Poursadeqi
1135
1135
4
Look into using the wait command.
â Raman Sailopal
Jan 22 at 8:57
add a comment |Â
4
Look into using the wait command.
â Raman Sailopal
Jan 22 at 8:57
4
4
Look into using the wait command.
â Raman Sailopal
Jan 22 at 8:57
Look into using the wait command.
â Raman Sailopal
Jan 22 at 8:57
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
command1 &
command2 &
wait
echo 'command1 and command2 have finished'
command3 &
command4 &
wait
echo 'command3 and command4 have finished'
The call to wait
will pause the script until all backgrounded tasks have finished executing.
Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):
( command1; command2 ) &
echo 'command1 and command2 are running'
wait
echo 'command1 and command2 have finished'
In the above case, command1
and command2
will run in the background, but not concurrently with each other.
Doing
command1 & command2
wait
is equivalent to
command1 &
command2
wait
... which will work, but command2
will not be running in the background and wait
will not be called until command2
has finished executing.
add a comment |Â
up vote
1
down vote
The actual answer of my question was something like this, special thanks from @raman-sailopal
command1 & command2
wait
echo "command 1 and 2 has finished"
command3 & command4
That will work, but thuwait
will only wait forcommand1
ascommand2
is not run as a background task. The same goes forcommand4
.
â Kusalananda
Jan 22 at 9:55
add a comment |Â
up vote
0
down vote
command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"
&
runs commands simultaneously
;
emulates a new line - i.e. will be run after completion
&&
runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)
This doesnâÂÂt work:command1
will run in the background, the firstecho
will run as soon ascommand2
completes, regardless of whethercommand1
has finished. Likewise forcommand3
.
â Stephen Kitt
Jan 22 at 9:45
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
command1 &
command2 &
wait
echo 'command1 and command2 have finished'
command3 &
command4 &
wait
echo 'command3 and command4 have finished'
The call to wait
will pause the script until all backgrounded tasks have finished executing.
Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):
( command1; command2 ) &
echo 'command1 and command2 are running'
wait
echo 'command1 and command2 have finished'
In the above case, command1
and command2
will run in the background, but not concurrently with each other.
Doing
command1 & command2
wait
is equivalent to
command1 &
command2
wait
... which will work, but command2
will not be running in the background and wait
will not be called until command2
has finished executing.
add a comment |Â
up vote
2
down vote
accepted
command1 &
command2 &
wait
echo 'command1 and command2 have finished'
command3 &
command4 &
wait
echo 'command3 and command4 have finished'
The call to wait
will pause the script until all backgrounded tasks have finished executing.
Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):
( command1; command2 ) &
echo 'command1 and command2 are running'
wait
echo 'command1 and command2 have finished'
In the above case, command1
and command2
will run in the background, but not concurrently with each other.
Doing
command1 & command2
wait
is equivalent to
command1 &
command2
wait
... which will work, but command2
will not be running in the background and wait
will not be called until command2
has finished executing.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
command1 &
command2 &
wait
echo 'command1 and command2 have finished'
command3 &
command4 &
wait
echo 'command3 and command4 have finished'
The call to wait
will pause the script until all backgrounded tasks have finished executing.
Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):
( command1; command2 ) &
echo 'command1 and command2 are running'
wait
echo 'command1 and command2 have finished'
In the above case, command1
and command2
will run in the background, but not concurrently with each other.
Doing
command1 & command2
wait
is equivalent to
command1 &
command2
wait
... which will work, but command2
will not be running in the background and wait
will not be called until command2
has finished executing.
command1 &
command2 &
wait
echo 'command1 and command2 have finished'
command3 &
command4 &
wait
echo 'command3 and command4 have finished'
The call to wait
will pause the script until all backgrounded tasks have finished executing.
Alternatively (just "for your information"), depending on whether you want command 1 and 2 to run concurrently or not (equivalently for command 3 and 4):
( command1; command2 ) &
echo 'command1 and command2 are running'
wait
echo 'command1 and command2 have finished'
In the above case, command1
and command2
will run in the background, but not concurrently with each other.
Doing
command1 & command2
wait
is equivalent to
command1 &
command2
wait
... which will work, but command2
will not be running in the background and wait
will not be called until command2
has finished executing.
answered Jan 22 at 10:00
Kusalananda
103k13202319
103k13202319
add a comment |Â
add a comment |Â
up vote
1
down vote
The actual answer of my question was something like this, special thanks from @raman-sailopal
command1 & command2
wait
echo "command 1 and 2 has finished"
command3 & command4
That will work, but thuwait
will only wait forcommand1
ascommand2
is not run as a background task. The same goes forcommand4
.
â Kusalananda
Jan 22 at 9:55
add a comment |Â
up vote
1
down vote
The actual answer of my question was something like this, special thanks from @raman-sailopal
command1 & command2
wait
echo "command 1 and 2 has finished"
command3 & command4
That will work, but thuwait
will only wait forcommand1
ascommand2
is not run as a background task. The same goes forcommand4
.
â Kusalananda
Jan 22 at 9:55
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The actual answer of my question was something like this, special thanks from @raman-sailopal
command1 & command2
wait
echo "command 1 and 2 has finished"
command3 & command4
The actual answer of my question was something like this, special thanks from @raman-sailopal
command1 & command2
wait
echo "command 1 and 2 has finished"
command3 & command4
answered Jan 22 at 9:40
Ebrahim Poursadeqi
1135
1135
That will work, but thuwait
will only wait forcommand1
ascommand2
is not run as a background task. The same goes forcommand4
.
â Kusalananda
Jan 22 at 9:55
add a comment |Â
That will work, but thuwait
will only wait forcommand1
ascommand2
is not run as a background task. The same goes forcommand4
.
â Kusalananda
Jan 22 at 9:55
That will work, but thu
wait
will only wait for command1
as command2
is not run as a background task. The same goes for command4
.â Kusalananda
Jan 22 at 9:55
That will work, but thu
wait
will only wait for command1
as command2
is not run as a background task. The same goes for command4
.â Kusalananda
Jan 22 at 9:55
add a comment |Â
up vote
0
down vote
command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"
&
runs commands simultaneously
;
emulates a new line - i.e. will be run after completion
&&
runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)
This doesnâÂÂt work:command1
will run in the background, the firstecho
will run as soon ascommand2
completes, regardless of whethercommand1
has finished. Likewise forcommand3
.
â Stephen Kitt
Jan 22 at 9:45
add a comment |Â
up vote
0
down vote
command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"
&
runs commands simultaneously
;
emulates a new line - i.e. will be run after completion
&&
runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)
This doesnâÂÂt work:command1
will run in the background, the firstecho
will run as soon ascommand2
completes, regardless of whethercommand1
has finished. Likewise forcommand3
.
â Stephen Kitt
Jan 22 at 9:45
add a comment |Â
up vote
0
down vote
up vote
0
down vote
command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"
&
runs commands simultaneously
;
emulates a new line - i.e. will be run after completion
&&
runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)
command1 & command2; echo "command1 & 2 complete" && command3 & command4; echo "command3 & 4 complete"
&
runs commands simultaneously
;
emulates a new line - i.e. will be run after completion
&&
runs once the previous job has finished, provided the previous job was successful (i.e. didn't return any exit code but 0)
answered Jan 22 at 9:31
RobotJohnny
438213
438213
This doesnâÂÂt work:command1
will run in the background, the firstecho
will run as soon ascommand2
completes, regardless of whethercommand1
has finished. Likewise forcommand3
.
â Stephen Kitt
Jan 22 at 9:45
add a comment |Â
This doesnâÂÂt work:command1
will run in the background, the firstecho
will run as soon ascommand2
completes, regardless of whethercommand1
has finished. Likewise forcommand3
.
â Stephen Kitt
Jan 22 at 9:45
This doesnâÂÂt work:
command1
will run in the background, the first echo
will run as soon as command2
completes, regardless of whether command1
has finished. Likewise for command3
.â Stephen Kitt
Jan 22 at 9:45
This doesnâÂÂt work:
command1
will run in the background, the first echo
will run as soon as command2
completes, regardless of whether command1
has finished. Likewise for command3
.â Stephen Kitt
Jan 22 at 9:45
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418796%2frun-bunch-of-commands-and-wait%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
4
Look into using the wait command.
â Raman Sailopal
Jan 22 at 8:57