Jump to content

How do I run a command when another is on the run? in sh

eengamerjens
Go to solution Solved by Tomsen,

You can't run them all at once, but by adding a single '&' at the end, will put the running command in the background (and will allow the next command to run immediately).

Example:

 

#! /bin/bash
clear
timeout 60s
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/BungeeCord; java -Xmx100M -Xms100M -jar BungeeCord.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/lobby; java -Xmx785M -Xms785M -jar spigot.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/factions; java -Xmx785M -Xms785M -jar spigot.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/plots; java -Xmx785M -Xms785M -jar spigot.jar" &

 

hallo you all

 

i want dis to start all to Together at once?

in shell                    

help!                       

 

                           code

                           vvvv

---------------------------------------------------------------

#! /bin/bash
clear
timeout 60s
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/BungeeCord; java -Xmx100M -Xms100M -jar BungeeCord.jar"

xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/lobby; java -Xmx785M -Xms785M -jar spigot.jar"

xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/factions; java -Xmx785M -Xms785M -jar spigot.jar"

xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/plots; java -Xmx785M -Xms785M -jar spigot.jar"

---------------------------------------------------------------

 

a video of what is happening.mp4

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

have you tried adding && between them? I used to do that when doing apt-update.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

You can't run them all at once, but by adding a single '&' at the end, will put the running command in the background (and will allow the next command to run immediately).

Example:

 

#! /bin/bash
clear
timeout 60s
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/BungeeCord; java -Xmx100M -Xms100M -jar BungeeCord.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/lobby; java -Xmx785M -Xms785M -jar spigot.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/factions; java -Xmx785M -Xms785M -jar spigot.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/plots; java -Xmx785M -Xms785M -jar spigot.jar" &

 

Please avoid feeding the argumentative narcissistic academic monkey.

"the last 20 percent – going from demo to production-worthy algorithm – is both hard and is time-consuming. The last 20 percent is what separates the men from the boys" - Mobileye CEO

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, vorticalbox said:

have you tried adding && between them? I used to do that when doing apt-update.

I believe this runs the first command and then if it was successful the next command is run after, so not at the same time

&& would work well for apt-update && apt-upgrade though :)

Link to comment
Share on other sites

Link to post
Share on other sites

As @Tomsen mentioned, you can't run their simultaneously, and you might want to try his solution. Mine would using a programming language that supports forks , like C or C++. This way you could run each command as a different process.

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, Tomsen said:

You can't run them all at once, but by adding a single '&' at the end, will put the running command in the background (and will allow the next command to run immediately).

Example:

 


#! /bin/bash
clear
timeout 60s
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/BungeeCord; java -Xmx100M -Xms100M -jar BungeeCord.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/lobby; java -Xmx785M -Xms785M -jar spigot.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/factions; java -Xmx785M -Xms785M -jar spigot.jar" &
xterm -e sh -c "cd /home/minecraftserver/Desktop/test-server/plots; java -Xmx785M -Xms785M -jar spigot.jar" &

 

THX men 

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, IAmAndre said:

As @Tomsen mentioned, you can't run their simultaneously, and you might want to try his solution. Mine would using a programming language that supports forks , like C or C++. This way you could run each command as a different process.

Going from a scripting language to a low-level system language, might be a slight to big of a jump. He only provokes an external application from commandline (from what we can see), so I would think c/c++ would be kind of a waste. The language should depend on the script/application/work-requirements and whatnot.

 

The method I used, is basically bash's implementation of fork (not as capable as c/c++'s), but still do the job in a nicely manner.

It essentially creates a child-process, run it is a sub-shell, with the running command(s) (you can use '()' to encapsulate multiple lines).

Please avoid feeding the argumentative narcissistic academic monkey.

"the last 20 percent – going from demo to production-worthy algorithm – is both hard and is time-consuming. The last 20 percent is what separates the men from the boys" - Mobileye CEO

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×