-1

I actually want to run some commands of the same script on different tabs or terminal because these commands are activating servers and listening to different ports. So they have to be always active. As well, I want to have a reference to the tab or the terminal so that I can later shut them down at the end of the script. Help please.

I tried a simple script test to see if I could find a way for opening other tabs :

tab=" --tab"
options=()

cmds[1]="echo Banana"

cmds[2]="echo Cat"


for i in 1 2; do
options+=($tab  -e "bash -c \"${cmds[i]} ; bash\"" ) 
done

gnome-terminal "${options[@]}"

exit 0

but I get this as a result :

./test.sh
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.

Is there any way to open tabs ? and get a reference to each one so that I can shut down commands related to servers once the treatment is done ?

Nada Touil
  • 317
  • 3
  • 12
  • I suggest to take a look at `man screen`. – Cyrus Aug 15 '19 at 09:32
  • no manual found for screen – Nada Touil Aug 15 '19 at 09:40
  • You will want to install `screen` or `tmux`, they are not part of the standard base install on most OSes but very commonly installed by admins. If you have to pick one or the other, many people recommend `tmux` as more modern and modular. – tripleee Aug 15 '19 at 10:14
  • You can find manual pages for all standard utilities and a lot of optional ones in Google if you don't have them installed locally. Here's [`man screen`](http://man7.org/linux/man-pages/man1/screen.1.html) and here's [`man tmux`](http://man7.org/linux/man-pages/man1/tmux.1.html). However, as you probably know, the manual page is a reference, not a tutorial. Perhaps find a tutorial for the one you are interested in for a start. – tripleee Aug 15 '19 at 10:15

2 Answers2

2

You could use a programm called tmux. It's a terminal-multiplexer, like screen. With that you can open different sessions and windows (these are like tabs) in the same terminal window. They can be referenced by name or id via script.

It's very probable, that the package manager of your Linux distribution has tmux.

P.S: I have to post an answer instead of a comment as I don't have enough reputation for commenting.

m4110c
  • 427
  • 4
  • 10
0

This is what I found for man gnome-terminal ; I think that could help , thanks

gnome-terminal(1)           General Commands Manual          gnome-terminal(1)

NAME
       gnome-terminal — is a terminal emulation application.

SYNOPSIS
       gnome-terminal  [-e,  --command=STRING]   [-x,  --execute ]  [--window-
       with-profile=PROFILENAME]  [--tab-with-profile=PROFILENAME]  [--window-
       with-profile-internal-id=PROFILEID]       [--tab-with-profile-internal-
       id=PROFILEID]    [--role=ROLE]    [--show-menubar]     [--hide-menubar]
       [--geometry=GEOMETRY]  [--working-directory=DIRNAME]  [-?, --help]

DESCRIPTION
       GNOME  Terminal is a terminal emulation application that you can use to
       perform the following actions:

       Access a UNIX shell in the GNOME environment.

       A shell is a program that interprets and executes the commands that you
       type  at  a  command  line  prompt.  When you start GNOME Terminal, the
       application starts the default shell that is specified in  your  system
       account. You can switch to a different shell at any time.
OPTIONS
       -e, --command=STRING
                 Execute the argument to this option inside the terminal.

       -x, --execute
                 Execute  the  remainder of the command line inside the termi‐
                 nal.

       --window-with-profile=PROFILENAME
                 Open a new window containing a tab with  the  given  profile.
                 More than one of these options can be provided.

       --tab-with-profile=PROFILENAME
                 Open  a  tab  in the window with the given profile. More than
                 one of these options can be provided, to open several tabs .

       --window-with-profile-internal-id=PROFILEID
                 Open a new window containing a tab with the given profile ID.
                 Used internally to save sessions.

Nada Touil
  • 317
  • 3
  • 12