I'm trying to set up a script that opens a terminal, does an ssh to a remote server, and executes a command (tail -F logfile in my case).
What I have so far is the following
gnome-terminal -e 'ssh -t server "tail -F logfile"'
This works to some extent. -t ensures that signals like SIGINT are sent through the commands running remotely.
However, when I ctrl-c the tail, I would really like to drop down to a bash terminal on the remote server. Right now, if I ctrl-c the tail, then the tail is closed, which causes ssh to exit, which causes the whole terminal to be closed.
What I would like is for the tail to be terminated and be left with a bash shell on the remote server.
I have tried the following:
gnome-terminal -e 'ssh -t server "tail -F logfile; /bin/bash"'
but that doesn't seem to work. That is, if I run this without gnome-terminal, just ssh -t ..., then see the following:
some lines
from the log
^CConnection to server closed.
But, If I do
gnome-terminal -e 'ssh -t server "nonexistantcommand; /bin/bash"'
Then I get an error that nonexistantcommand is not found, and then I do drop down to a bash on a remote server...
Does anyone have any suggestions or hints on how to get this going? Thanks in advance.
Here, have a nasty hack:
gnome-terminal -e 'ssh -t server "echo \"tail -F logfile;rm /tmp/foo\" > /tmp/foo; bash --rcfile /tmp/foo"'
--init-file filename
--rcfile filename
Execute commands from filename (instead of `~/.bashrc') in an interactive shell.
so run bash with --rcfile pointing to a script running tail -F.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With