How to run sequentially two tasks on linux [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm using a keycloak server, when I run this command:
standalone.sh
This command launchs the server and I'm not able to stop it until I execute Ctrl-C command. I though about runing an instruction like this:
standalone.sh && jboss-cli.sh -c --commands=shutdown
or
standalone.sh ; jboss-cli.sh -c --commands=shutdown
Based on this question What are the shell's control and redirection operators? I found that ;
Will run one command after another has finished, irrespective of the outcome of the first.
And &&
Used to build AND lists, it allows you to run one command only if another exited successfully.
But in my case the first task did not exit and still executing. Is there any solution to run another task which will stop the first?
shell-script control-flow
closed as unclear what you're asking by Kusalananda, roaima, mdpc, G-Man, Archemar Mar 6 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
 |Â
show 2 more comments
up vote
0
down vote
favorite
I'm using a keycloak server, when I run this command:
standalone.sh
This command launchs the server and I'm not able to stop it until I execute Ctrl-C command. I though about runing an instruction like this:
standalone.sh && jboss-cli.sh -c --commands=shutdown
or
standalone.sh ; jboss-cli.sh -c --commands=shutdown
Based on this question What are the shell's control and redirection operators? I found that ;
Will run one command after another has finished, irrespective of the outcome of the first.
And &&
Used to build AND lists, it allows you to run one command only if another exited successfully.
But in my case the first task did not exit and still executing. Is there any solution to run another task which will stop the first?
shell-script control-flow
closed as unclear what you're asking by Kusalananda, roaima, mdpc, G-Man, Archemar Mar 6 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Does the second command stop the first? When would you want to run that second command? After a certain time?
â Kusalananda
Mar 5 at 13:24
@Kusalananda yes the second will stop the first after the first will be executed
â para 008
Mar 5 at 13:25
But the first one does not finish? I'm assuming it's running something in the foreground that prevent it from actually exiting and giving back control to you script. What does the first script look like?
â Kusalananda
Mar 5 at 13:26
1
Are you just looking for&
? Runningstandalone.sh &
will run it in the background, so you will still have access to the terminal and can runjboss-cli.sh -c --commands=shutdown
whenever you want.
â terdonâ¦
Mar 5 at 13:31
1
This question is unclear: It is unclear whether you want to start the keycloak server with the first script and the immediately shut it down with the second command, or whether the first script is supposed to start the server, do some things, and then the server should be shut down. We don't know what your first script is doing or what it needs to do.
â Kusalananda
Mar 5 at 14:27
 |Â
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using a keycloak server, when I run this command:
standalone.sh
This command launchs the server and I'm not able to stop it until I execute Ctrl-C command. I though about runing an instruction like this:
standalone.sh && jboss-cli.sh -c --commands=shutdown
or
standalone.sh ; jboss-cli.sh -c --commands=shutdown
Based on this question What are the shell's control and redirection operators? I found that ;
Will run one command after another has finished, irrespective of the outcome of the first.
And &&
Used to build AND lists, it allows you to run one command only if another exited successfully.
But in my case the first task did not exit and still executing. Is there any solution to run another task which will stop the first?
shell-script control-flow
I'm using a keycloak server, when I run this command:
standalone.sh
This command launchs the server and I'm not able to stop it until I execute Ctrl-C command. I though about runing an instruction like this:
standalone.sh && jboss-cli.sh -c --commands=shutdown
or
standalone.sh ; jboss-cli.sh -c --commands=shutdown
Based on this question What are the shell's control and redirection operators? I found that ;
Will run one command after another has finished, irrespective of the outcome of the first.
And &&
Used to build AND lists, it allows you to run one command only if another exited successfully.
But in my case the first task did not exit and still executing. Is there any solution to run another task which will stop the first?
shell-script control-flow
edited Mar 5 at 13:24
Kusalananda
103k13202318
103k13202318
asked Mar 5 at 13:21
para 008
31
31
closed as unclear what you're asking by Kusalananda, roaima, mdpc, G-Man, Archemar Mar 6 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Kusalananda, roaima, mdpc, G-Man, Archemar Mar 6 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Does the second command stop the first? When would you want to run that second command? After a certain time?
â Kusalananda
Mar 5 at 13:24
@Kusalananda yes the second will stop the first after the first will be executed
â para 008
Mar 5 at 13:25
But the first one does not finish? I'm assuming it's running something in the foreground that prevent it from actually exiting and giving back control to you script. What does the first script look like?
â Kusalananda
Mar 5 at 13:26
1
Are you just looking for&
? Runningstandalone.sh &
will run it in the background, so you will still have access to the terminal and can runjboss-cli.sh -c --commands=shutdown
whenever you want.
â terdonâ¦
Mar 5 at 13:31
1
This question is unclear: It is unclear whether you want to start the keycloak server with the first script and the immediately shut it down with the second command, or whether the first script is supposed to start the server, do some things, and then the server should be shut down. We don't know what your first script is doing or what it needs to do.
â Kusalananda
Mar 5 at 14:27
 |Â
show 2 more comments
Does the second command stop the first? When would you want to run that second command? After a certain time?
â Kusalananda
Mar 5 at 13:24
@Kusalananda yes the second will stop the first after the first will be executed
â para 008
Mar 5 at 13:25
But the first one does not finish? I'm assuming it's running something in the foreground that prevent it from actually exiting and giving back control to you script. What does the first script look like?
â Kusalananda
Mar 5 at 13:26
1
Are you just looking for&
? Runningstandalone.sh &
will run it in the background, so you will still have access to the terminal and can runjboss-cli.sh -c --commands=shutdown
whenever you want.
â terdonâ¦
Mar 5 at 13:31
1
This question is unclear: It is unclear whether you want to start the keycloak server with the first script and the immediately shut it down with the second command, or whether the first script is supposed to start the server, do some things, and then the server should be shut down. We don't know what your first script is doing or what it needs to do.
â Kusalananda
Mar 5 at 14:27
Does the second command stop the first? When would you want to run that second command? After a certain time?
â Kusalananda
Mar 5 at 13:24
Does the second command stop the first? When would you want to run that second command? After a certain time?
â Kusalananda
Mar 5 at 13:24
@Kusalananda yes the second will stop the first after the first will be executed
â para 008
Mar 5 at 13:25
@Kusalananda yes the second will stop the first after the first will be executed
â para 008
Mar 5 at 13:25
But the first one does not finish? I'm assuming it's running something in the foreground that prevent it from actually exiting and giving back control to you script. What does the first script look like?
â Kusalananda
Mar 5 at 13:26
But the first one does not finish? I'm assuming it's running something in the foreground that prevent it from actually exiting and giving back control to you script. What does the first script look like?
â Kusalananda
Mar 5 at 13:26
1
1
Are you just looking for
&
? Running standalone.sh &
will run it in the background, so you will still have access to the terminal and can run jboss-cli.sh -c --commands=shutdown
whenever you want.â terdonâ¦
Mar 5 at 13:31
Are you just looking for
&
? Running standalone.sh &
will run it in the background, so you will still have access to the terminal and can run jboss-cli.sh -c --commands=shutdown
whenever you want.â terdonâ¦
Mar 5 at 13:31
1
1
This question is unclear: It is unclear whether you want to start the keycloak server with the first script and the immediately shut it down with the second command, or whether the first script is supposed to start the server, do some things, and then the server should be shut down. We don't know what your first script is doing or what it needs to do.
â Kusalananda
Mar 5 at 14:27
This question is unclear: It is unclear whether you want to start the keycloak server with the first script and the immediately shut it down with the second command, or whether the first script is supposed to start the server, do some things, and then the server should be shut down. We don't know what your first script is doing or what it needs to do.
â Kusalananda
Mar 5 at 14:27
 |Â
show 2 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Add a single &
at the end of the first command.
standalone.sh & jboss-cli.sh -c --commands=shutdown
That single ampersand is a command delimiter, just like ;
, but sends the prior command to run asynchronously, in the background, and lets the following command(s) start immediately.
1
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
@Kusalananda - no, it should not. Fromman bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instancexclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)
â user1404316
Mar 5 at 14:11
@Kusalananda - you may be confusing the ampersand delimiter with theC-z
"suspend" keybinding.
â user1404316
Mar 5 at 14:15
1
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you runstart-service-script & shutdown-service-command
then the service will not be running for very long.
â Kusalananda
Mar 5 at 14:24
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
add a comment |Â
up vote
1
down vote
As noted by user1404316, standalone.sh & jboss-cli.sh -c --commands=shutdown
is probably what you want. The only issue with that is that if the standalone.sh
takes time to execute (which it probably does), I would insert a sleep
to offset the execution time such as:
standalone.sh & sleep $amount_of_time_in_seconds; jboss-cli.sh -c --commands=shutdown
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Add a single &
at the end of the first command.
standalone.sh & jboss-cli.sh -c --commands=shutdown
That single ampersand is a command delimiter, just like ;
, but sends the prior command to run asynchronously, in the background, and lets the following command(s) start immediately.
1
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
@Kusalananda - no, it should not. Fromman bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instancexclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)
â user1404316
Mar 5 at 14:11
@Kusalananda - you may be confusing the ampersand delimiter with theC-z
"suspend" keybinding.
â user1404316
Mar 5 at 14:15
1
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you runstart-service-script & shutdown-service-command
then the service will not be running for very long.
â Kusalananda
Mar 5 at 14:24
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
add a comment |Â
up vote
1
down vote
accepted
Add a single &
at the end of the first command.
standalone.sh & jboss-cli.sh -c --commands=shutdown
That single ampersand is a command delimiter, just like ;
, but sends the prior command to run asynchronously, in the background, and lets the following command(s) start immediately.
1
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
@Kusalananda - no, it should not. Fromman bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instancexclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)
â user1404316
Mar 5 at 14:11
@Kusalananda - you may be confusing the ampersand delimiter with theC-z
"suspend" keybinding.
â user1404316
Mar 5 at 14:15
1
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you runstart-service-script & shutdown-service-command
then the service will not be running for very long.
â Kusalananda
Mar 5 at 14:24
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Add a single &
at the end of the first command.
standalone.sh & jboss-cli.sh -c --commands=shutdown
That single ampersand is a command delimiter, just like ;
, but sends the prior command to run asynchronously, in the background, and lets the following command(s) start immediately.
Add a single &
at the end of the first command.
standalone.sh & jboss-cli.sh -c --commands=shutdown
That single ampersand is a command delimiter, just like ;
, but sends the prior command to run asynchronously, in the background, and lets the following command(s) start immediately.
answered Mar 5 at 13:41
user1404316
2,314520
2,314520
1
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
@Kusalananda - no, it should not. Fromman bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instancexclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)
â user1404316
Mar 5 at 14:11
@Kusalananda - you may be confusing the ampersand delimiter with theC-z
"suspend" keybinding.
â user1404316
Mar 5 at 14:15
1
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you runstart-service-script & shutdown-service-command
then the service will not be running for very long.
â Kusalananda
Mar 5 at 14:24
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
add a comment |Â
1
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
@Kusalananda - no, it should not. Fromman bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instancexclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)
â user1404316
Mar 5 at 14:11
@Kusalananda - you may be confusing the ampersand delimiter with theC-z
"suspend" keybinding.
â user1404316
Mar 5 at 14:15
1
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you runstart-service-script & shutdown-service-command
then the service will not be running for very long.
â Kusalananda
Mar 5 at 14:24
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
1
1
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
This will also stop the first task immediately, which may not be wanted (?)
â Kusalananda
Mar 5 at 13:48
@Kusalananda - no, it should not. From
man bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instance xclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)â user1404316
Mar 5 at 14:11
@Kusalananda - no, it should not. From
man bash
: "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Try, for instance xclock -digital -update 1 & xclock -digital -update 1
(The second instance may overlay the first, so you may need to move the top window)â user1404316
Mar 5 at 14:11
@Kusalananda - you may be confusing the ampersand delimiter with the
C-z
"suspend" keybinding.â user1404316
Mar 5 at 14:15
@Kusalananda - you may be confusing the ampersand delimiter with the
C-z
"suspend" keybinding.â user1404316
Mar 5 at 14:15
1
1
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you run
start-service-script & shutdown-service-command
then the service will not be running for very long.â Kusalananda
Mar 5 at 14:24
What I mean is that if I'm reading the question correctly, the first script will start some servire, and the second command will shut it down. If you run
start-service-script & shutdown-service-command
then the service will not be running for very long.â Kusalananda
Mar 5 at 14:24
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
@Kusalananda - yes, that is exactly what the OP is indicating in his example, which I reflected back to him/her. Your comment is probably best directed at the OP, so we can both know for sure the intent, but I suspect it was just presented as an example.
â user1404316
Mar 5 at 14:30
add a comment |Â
up vote
1
down vote
As noted by user1404316, standalone.sh & jboss-cli.sh -c --commands=shutdown
is probably what you want. The only issue with that is that if the standalone.sh
takes time to execute (which it probably does), I would insert a sleep
to offset the execution time such as:
standalone.sh & sleep $amount_of_time_in_seconds; jboss-cli.sh -c --commands=shutdown
add a comment |Â
up vote
1
down vote
As noted by user1404316, standalone.sh & jboss-cli.sh -c --commands=shutdown
is probably what you want. The only issue with that is that if the standalone.sh
takes time to execute (which it probably does), I would insert a sleep
to offset the execution time such as:
standalone.sh & sleep $amount_of_time_in_seconds; jboss-cli.sh -c --commands=shutdown
add a comment |Â
up vote
1
down vote
up vote
1
down vote
As noted by user1404316, standalone.sh & jboss-cli.sh -c --commands=shutdown
is probably what you want. The only issue with that is that if the standalone.sh
takes time to execute (which it probably does), I would insert a sleep
to offset the execution time such as:
standalone.sh & sleep $amount_of_time_in_seconds; jboss-cli.sh -c --commands=shutdown
As noted by user1404316, standalone.sh & jboss-cli.sh -c --commands=shutdown
is probably what you want. The only issue with that is that if the standalone.sh
takes time to execute (which it probably does), I would insert a sleep
to offset the execution time such as:
standalone.sh & sleep $amount_of_time_in_seconds; jboss-cli.sh -c --commands=shutdown
edited Mar 5 at 17:38
answered Mar 5 at 13:45
Jaken551
1678
1678
add a comment |Â
add a comment |Â
Does the second command stop the first? When would you want to run that second command? After a certain time?
â Kusalananda
Mar 5 at 13:24
@Kusalananda yes the second will stop the first after the first will be executed
â para 008
Mar 5 at 13:25
But the first one does not finish? I'm assuming it's running something in the foreground that prevent it from actually exiting and giving back control to you script. What does the first script look like?
â Kusalananda
Mar 5 at 13:26
1
Are you just looking for
&
? Runningstandalone.sh &
will run it in the background, so you will still have access to the terminal and can runjboss-cli.sh -c --commands=shutdown
whenever you want.â terdonâ¦
Mar 5 at 13:31
1
This question is unclear: It is unclear whether you want to start the keycloak server with the first script and the immediately shut it down with the second command, or whether the first script is supposed to start the server, do some things, and then the server should be shut down. We don't know what your first script is doing or what it needs to do.
â Kusalananda
Mar 5 at 14:27