18

This is what I want to accomplish:

  1. I want to open a gnome terminal with five tabs in it
  2. I want to run a set of commands (5 – 10 commands) in each tab automatically
    First tab: shall set clear-case view and after that execute one or more commands
    Second tab: shall login into a server and execute some commands
    Third tab: shall only execute some commands

gnome-terminal --geometry=260x25-0+0 --tab -e "csh -c \"ct setview myViewName; cal\"" –tab --tab --tab (works ok, view is set but no command executed after that)

I have tried to do it this way instead and running this in the script below:

gnome-terminal --geometry 125x18-0-26 --tab -t "some title" -e /home/ekido/Desktop/MyScripts/myScript

#!/usr/bin/expect
exec gnome-terminal --geometry 125x49-0+81 –tab
spawn ssh usert@server
expect "password"
send "*******\r"
expect "user@server100:~>"
send “some command\r"
expect "user@server100:~>"
send “some command"
interact 

If I remove the exec gnome-terminal --geometry 125x49-0+81 –tab rows from the example and call a script from some other file, it works fine -- I get logged in to the server and all commands executed. Can anyone help me solve this?

To write a script that I call for every tab is not an option, since I will have 5 terminals with 5-7 tabs in each in the end, and that means it would be 25 to 30 scripts to write (cost more than it helps in my problem).

1
  • Not that I'm an expert in GNOME Terminal, but the tabs you create should be saved in a profile. After creating the profile, I believe you can script it. See Manage Profiles in the GNOME Help.
    – eyoung100
    Sep 30, 2014 at 14:49

4 Answers 4

16

This seems to work on my machine:

gnome-terminal --geometry=260x25-0+0 --tab -e "bash -c 'date; read -n1'" --tab -e "bash -c 'echo meow; read -n1' " --tab --tab

Please note, as soon as the processes executed by -e are done running, they will terminate. In this case, bash is loaded, runs whatever commands you pass to it, and immediately exists. I put in the read statements to wait for user input. This way those tabs won't close until you press a key, just so you can see it in this example. Without them, it would look as if only two tabs opened, because the other two would execute and close too quickly.

2
  • thanks for your answer. Sure, I get to se the output of one command (in this case "date") but I would like to execute several commands, be able to se the output and then continue to write new commands manually in the same tab.
    – ekido
    Oct 1, 2014 at 8:27
  • 1
    Note that -e has been deprecated in newer versions of gnome-terminal, which makes it more tricky to answer the question. To prepare for the deprecation, the best I could come up with is this solution.
    – bluenote10
    Mar 4, 2021 at 10:46
4

Since bash quits after the command completes, you can call another instance of bash after your command to get an interactive shell:

gnome-terminal  --tab -e "bash -c 'ps -ef; bash'" --tab -e "bash -c 'ls; bash'" --tab -e "bash -c 'top -n 1; bash'"
1
  • it seems that if I close the terminal the underlying processes dont close automatically, is there a solution to this too? I would like to close the entire window and all tabs with their processes should get a kill
    – Blub
    Sep 15, 2018 at 7:12
4

Save below as script.sh

#!/usr/bin/env bash

me=$(realpath $0)

commands=(
"echo"
"ls -l && echo 'yes'"
"top"
"ps"
)
len=${#commands[@]}

if [ $# -eq 0 ];then
    num=$len
else
    num=$1
fi

n=$((len-num))
command=${commands[$n]}
num=$((num-1))

xdotool key ctrl+shift+t

if [ $num -gt -1 ]; then
    sleep 1; xdotool type --delay 1 --clearmodifiers "$me $num; ${command}"; xdotool key Return;
fi

add script.sh to $PATH then run it

gnome-terminal -x script.sh

See Open a new tab in gnome-terminal using command line.

2
  • everything else failed apart form this. Now, i would like to have some of the tabs open without a command. For example, i would like to have ten tabs open, but three if them could be running some commands like htop..
    – nyxee
    Dec 2, 2019 at 15:04
  • 1
    How would you do this so the script also launches the gnome-terminal? Mar 16, 2021 at 19:29
0

If you want to strictly use the GUI:

  1. (Once in terminator) right-click in the terminal area and select Open Tab for however many tabs you want
  2. Either: Click the icon in the top right of the terminal area (not the title bar) and select Broadcast All OR select New Group - pick a name For each tab, click this icon and select the group just created Click this icon and select Broadcast Group

Now anything typed in ANY tab will be replicated to all tabs. Broadcast Off turns the feature off.

For a variant, install KDE's konsole. Double-click free space across the bottom to create multiple tabs. Next, select Edit->Copy Input To and pick how you want to copy. Everything you type in THAT tab (in contrast to terminator's "any tab") will be replicated to all selected tabs. Copy Input To->None turns the feature off.

A final variant is clusterssh.

If you use this feature be very careful (or avoid) using vi - it has too many configuration possibilities concerning how it interprets some keystrokes to be sure it will do what you want. The same is true (for a different reason) if you use bash' search history features - be very sure you find the same thing in all terminal sessions.

1
  • 2
    This seems to be a very manual process — the question asks for a way to automate a task — and it doesn’t seem to accomplish what the OP wants.  Please describe how this answers the question. … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Oct 9, 2020 at 23:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .