1

My question is similar to this question.

I would like to open multiple terminal windows and execute commands in them by using a shell script. Since I want to monitor data, the terminals need to stay open.

My problem is as follows; I want to be able to execute commands in terminals that are already open and, more importantly, after I already executed commands in another terminal. This is what I have until now:

#!/bin/sh

terminator -T "terminal1" -e "[COMMAND]; [COMMAND]; $SHELL" &&
terminator -T "terminal2" -e "[COMMAND]; [COMMAND]; $SHELL"

#How to use terminal1 again here?

I cannot figure out how to do the last step here.

I am using Terminator, but any other terminal would also be fine.

1 Answers1

1

Consider using screen like that:

#!/bin/sh

terminator -T "terminal1" -e 'screen -S session-name1' &
terminator -T "terminal2" -e 'screen -S session-name2' &

# wait for terminators screen to show up and screen sessions to start
sleep 1

printf "Run command in terminal1\n"
screen -S session-name1 -X stuff "echo bye\n"

sleep 2
printf "Run command in terminal2\n"
screen -S session-name2 -X stuff "echo bye\n"

sleep 2
printf "Exit\n"
screen -S session-name1 -X stuff "exit\n"
screen -S session-name2 -X stuff "exit\n"