通过 ssh 执行命令,然后运行 bash
我正在尝试设置一个脚本来打开终端、通过 ssh 连接到远程服务器并执行命令(在我的例子中为 tail -F 日志文件)。
到目前为止,我所拥有的是以下内容
gnome-terminal -e 'ssh -t server "tail -F logfile"'
这在某种程度上有效。 -t 确保通过远程运行的命令发送 SIGINT 等信号。
然而,当我 ctrl-c 尾部时,我真的很想下拉到远程服务器上的 bash 终端。现在,如果我 ctrl-c 尾部,则尾部关闭,这会导致 ssh 退出,从而导致整个终端关闭。
我想要的是终止 tail 并在远程服务器上留下 bash shell。
我已经尝试过以下方法:
gnome-terminal -e 'ssh -t server "tail -F logfile; /bin/bash"'
但这似乎不起作用。也就是说,如果我在没有 gnome-terminal 的情况下运行此命令,只需 ssh -t ...,然后看到以下内容:
some lines
from the log
^CConnection to server closed.
但是,如果我这样做
gnome-terminal -e 'ssh -t server "nonexistantcommand; /bin/bash"'
,那么我会收到一条错误,指出未找到 nonexistantcommand,然后我执行 下拉到远程服务器上的 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这里,有一个令人讨厌的黑客:
Here, have a nasty hack:
因此运行 bash 时使用 --rcfile 指向运行 tail -F 的脚本。
so run bash with --rcfile pointing to a script running tail -F.
为什么不做显而易见的事情呢? “如果您收到 SIGINT,请执行交互式 shell。”
Why not do the obvious? "If you got a SIGINT, execute an interactive shell."