Question:

Script to open multiple gnome-terminals with individual telnet sessions

Aubrey: 02 February 2022

I'm just curious if this is possible. I'm working with dynagen/qemu rather frequently (CCIE training), and would love to be able to run script 'x' to open 10 windows for me, all telnet'd to predefined ports.

IE:

new gnome-terminal opens -> telnet localhost 2001
new gnome-terminal opens -> telnet localhost 2002
new gnome-terminal opens -> telnet localhost 2003
new gnome-terminal opens -> telnet localhost 2004

etc,

I've done my fair share of googlin' and can't seem to come up with a straight answer.

Thanks for the help :)

Edit: This is how it's listening right now:

root@NiXToP:/home/***# netstat -na |grep 2001
tcp        0      0 0.0.0.0:2001            0.0.0.0:*               LISTEN    
root@NiXToP:/home/***# netstat -na |grep 2002
tcp        0      0 0.0.0.0:2002            0.0.0.0:*               LISTEN 
root@NiXToP:/home/***# netstat -na |grep 2003
tcp        0      0 0.0.0.0:2003            0.0.0.0:*               LISTEN

What telnet currently accomplishes:

# telnet localhost 2001
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connected to Dynamips VM "R1" (ID 0, type c3725) - Console port
R1>

Answer:
Ayla: 02 February 2022

You can use the -x or -e (http://manpages.ubuntu.com/manpages/precise/en/man1/gnome-terminal.1.html) options to run gnome-terminal and execute a specified command. For example:

gnome-terminal -x telnet miku.acm.uiuc.edu

So your script would execute gnome-terminal with the appropriate commands. If your port numbers are sequential you could do this with a loop:

#!/bin/sh
for PORT in $(seq 2001 2010); do
    gnome-terminal -x telnet localhost $PORT &
done