Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executing a command over ssh, and then running bash

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.

like image 263
vmpstr Avatar asked Oct 11 '22 16:10

vmpstr


2 Answers

Here, have a nasty hack:

gnome-terminal -e 'ssh -t server "echo \"tail -F logfile;rm /tmp/foo\" > /tmp/foo; bash --rcfile /tmp/foo"'
like image 153
chaos Avatar answered Oct 21 '22 05:10

chaos


--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.

like image 36
chx Avatar answered Oct 21 '22 07:10

chx