Ubuntu – How to open a new terminal window to ssh into a new computer and execute commands

command linegnomessh

Basically, I have a computer that I have to ssh into and pull up about 8 terminals to monitor various threads and log files. I would like to have a script from my build machine that can do this all for me. For example, if I want to watch the message queues, I'd like to run something like this:

gnome-terminal --window-with-profile=NOCLOSEPROFILE -e "ssh root@IP 'watch ipcs'" 

But the ssh command doesn't seem to execute properly. I've tried a dozen iterations of this, with no luck. Here is a screen shot, if that helps.

enter image description here

So basically, I want to have this be something I can put into a script, or even be something commandible, so given an ip address and a command to execute, I'd like a new terminal window to open an ssh connection to that ip and execute the command.

Thanks in advance

**EDIT
I seem to be able to do this and execute most commands with the above command, but the watch command does not work over ssh so perhaps the sytax isn't the problem. Is there a reason watch might not work here, where

gnome-terminal --window-with-profile=NOCLOSEPROFILE -e 'ssh -X root@$IP "tail -f /home/log/alog.log"'

works fine?

Best Answer

Rather than opening up multiple windows and establishing multiple ssh sessions (to the same machine?), take a look at screen. You can ssh to a host, start screen and from there open multiple virtual consoles, one for each command you want to run.

What's really nice about screen, is that if you loose the ssh connection, you can create a new one and reattach to the running screen sessions. It's really cool. There is also tmux, which is a similar program (not sure how available it is on different Linuxes.

Ref: http://en.wikipedia.org/wiki/GNU_Screen

Related Question