Linux – open gnome terminal with several tabs and execute a few commands in every tab

gnome-terminallinuxterminal

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).

Best Answer

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.

Related Question