I have scenario like below :
I have a bash file named infra.sh
. Inside this infra.sh file I have the below commands:
#!/bin/bash
gnome-terminal -e 'sh -c "bash ./redis-server.sh && sleep 30"'
gnome-terminal -e 'sh -c "bash ./redis-client.sh && sleep 30"'
gnome-terminal -e 'sh -c "bash ./playServer.sh && sleep 30"'
gnome-terminal -e 'sh -c "bash ./proclient-service.sh && sleep 30"'
gnome-terminal -e 'sh -c "bash ./infoServer.sh"'
Now if I execute the infra.sh
from a terminal by typing
sudo sh ./infra.sh
then, all the commands above gets executed in separate terminals. They are running.
But I want to make it in such a way that I will start the infra.sh
in a manner that all the services will be running in background and as well as the terminal from which I executed the commands for starting infra.sh
will also go in background.
Is it possible?
thanks in advance.
gnome-terminal
? If your goal is to preserve output, then consider usingscreen
instead. It's often used to start sessions on remote servers, where you can attach to session and detach whenever necessary and don't have to have terminal constantly open. See https://askubuntu.com/q/62562/295286 for details – Sergiy Kolodyazhnyy Dec 24 '18 at 10:54setsid
command. I'd make all commands be likesetsid ./redis-server.sh 2>&1 > /dev/null
and separate each on separate line withsleep 30
. See [related post] (https://askubuntu.com/a/106359/295286). If you do still care about preserving output,screen
which i mentioned already would be more appropriate. You could also consider making the script into a systemd service, but if there's no need to run it at boot, I wouldn't bother. I'd recommendsetsid
first – Sergiy Kolodyazhnyy Dec 24 '18 at 11:06