0

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.

George Udosen
  • 37,534

1 Answers1

2

Two options here:

  1. gnome-terminal <command> &: will run that command in the background but will be ended if the terminal is closed.

  2. nohup gnome-terminal <command> &: will run in background and keep running even if the terminal window is closed.

Now run that script with either & or nohup like so nohup sudo sh ./infra.sh & or sudo sh ./infra.sh &

George Udosen
  • 37,534