How can I launch multiple xterm windows and run a command on each, leaving each window open afterward?

user3609282 picture user3609282 · Dec 15, 2014 · Viewed 18.2k times · Source

I'm lazy, and I prefer that computers do my work for me. I ssh into several machines on a daily basis, so I created a simple script that launches some xterm windows and places them in positions I want (as you can see, I'm using bash):

#!/bin/bash
xterm -geometry 80x27+1930+0 &
xterm -geometry 80x27+2753+0 &
xterm -geometry 80x27+1930+626 &
xterm -geometry 80x27+2753+626 &

However, the next thing I do is go to the first window and type in

ssh server_a

then in the second

ssh server_b

and so on. What I'd like to do is have my script do the ssh commands in each xterm window, and then leave the windows open for me to do my work. I've seen the -e option for xterm, but the window closes after I execute my command. Is there a way to do this?

I apologize if this is a duplicate question. I've searched around and haven't had any luck with this. Many thanks!

Answer

Politank-Z picture Politank-Z · Dec 15, 2014

I'd love to see a more elegant answer, but what I came up with does work:

xterm -e bash -c 'echo foo; exec bash'

Replace echo foo with the command of your choice, and you're good to go.