How do I open a new terminal window to ssh into a new computer and execute commands?
Solution 1
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
Solution 2
You are trying to run an interactive command that requires a tty, and by default, ssh does not allocate a tty when you specify a command to be run on the remote machine. Add the -t
flag to force it to allocate a tty.
zachd1_618
Updated on September 18, 2022Comments
-
zachd1_618 over 1 year
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.
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 overssh
so perhaps the sytax isn't the problem. Is there a reasonwatch
might not work here, wheregnome-terminal --window-with-profile=NOCLOSEPROFILE -e 'ssh -X root@$IP "tail -f /home/log/alog.log"'
works fine?