5

This is a small shell script i wrote .

x-terminal-emulator -e "optirun yarpserver" &
sleep 6
x-terminal-emulator -e "optirun iCub_SIM" &
sleep 60
x-terminal-emulator -e "optirun simCartesianControl" &
sleep 30
x-terminal-emulator -e "optirun iKinCartesianSolver --context simCartesianControl/conf --part left_arm" &

What this does is , opens a new terminal for each program . What i want to do is open new terminal tab instead of a terminal . How should i go about doing this ?

rajat
  • 3,415
  • 15
  • 56
  • 90
  • 2
    You can do it in gnome-terminal: http://stackoverflow.com/questions/1188959/open-a-new-tab-in-gnome-terminal-using-command-line – Piotr Praszmo Oct 18 '12 at 18:52
  • 1
    I can't seem to understand the solution from the answers to that question , how can i do this on this script . can you please quickly elaborate ? – rajat Oct 18 '12 at 19:09
  • 1
    I was thinking about [this](http://stackoverflow.com/a/2164621/745924) answer. Something like [this](https://gist.github.com/3914197). – Piotr Praszmo Oct 18 '12 at 19:17
  • Works like a charm thanks :) , But only one problem i cannot see the first command which opens the yarpserver . it gets open as the other programs are able to connect to it but i can't see it . All the other 3 open in tabs. – rajat Oct 18 '12 at 19:32
  • This depends on terminal emulators. (Some emulators do not support tabs!) – weakish Sep 07 '13 at 12:09

2 Answers2

2

This thread is really old but if someone comes here, I leave a bash script that I created to launch multiple tabs to run different commands:

#!/bin/bash

# Array of commands to run in different tabs
commands=(
    'tail -f /var/log/apache2/access.log'
    'tail -f /var/log/apache2/error.log'
    'tail -f /usr/local/var/postgres/server.log'
)

# Build final command with all the tabs to launch
set finalCommand=""
for (( i = 0; i < ${#commands[@]}; i++ )); do
    export finalCommand+="--tab -e 'bash -c \"${commands[$i]}\"' "
done

# Run the final command
eval "gnome-terminal "$finalCommand

Just add the commands in the array and execute.

Source: http://joaoperibeiro.com/command-line-script-to-launch-multiple-tabs/

Joaopcribeiro
  • 91
  • 2
  • 6
0

I think your best option is to use tmux to do the job. Here just a quick example and a step by step explanation to it. Here I use only vertical splits which may be confusing you should read into the tmux manpage to see how to select-panes.

  • First create a new tmux session in detached mode
  • Then send the appropriate command to launch your first program
  • Create a new vertical Split
  • Send appropriate command to launch your second program
  • and so on ...
tmux new-session -d -s foo
tmux send-keys -t foo 'optirun yarpserver' Enter
tmux split-window -v -t foo
tmux send-keys -t foo 'optirun iCub_SIM' Enter
tmux split-window -v -t foo
tmux send-keys -t foo 'optirun simCartesianControl' Enter
tmux split-window -v -t foo
tmux send-keys -t foo 'optirun iKinCartesianSolver --context simCartesianControl/conf --part left_arm' Enter

Hope this helps you.

flazzarini
  • 7,791
  • 5
  • 33
  • 34