rju*_*ney 11 linux ssh remote openssh remote-control
我运行这个:
ssh -t -vvv -i ~/.ssh/druid-keypair -o StrictHostKeyChecking=no ubuntu@${INSTANCE_ADDRESS} <<EOI
# Setup Oracle Java
...
# Install dependencies - mysql must be built from source, as the 12.04 apt-get hangs
export DEBIAN_FRONTEND=noninteractive
sudo debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password password diurd'
sudo debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password_again password diurd'
sudo apt-get -q -y -V --force-yes --reinstall install mysql-server-5.5
echo "ALL DONE with druid environment setup!"
exit
EOI
Run Code Online (Sandbox Code Playgroud)
注意:我在 ssh 中尝试过使用和不使用 -t。
-vvv 的调试输出是这样的:
...
ldconfig deferred processing now taking place
ALL DONE with druid environment setup!
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Run Code Online (Sandbox Code Playgroud)
然后这个过程就永远停留在那里。为什么 ssh 命令不会结束?我试过 -t 和不带,我试过退出和不带。没什么区别:(
更新:当我在脚本末尾输入“jobs”时,我看到:
JOBS:
[1]- Running nohup bin/zookeeper-server-start.sh config/zookeeper.properties 2>&1 > /dev/null &
[2]+ Running nohup bin/kafka-server-start.sh config/server.properties 2>&1 > /dev/null &
Run Code Online (Sandbox Code Playgroud)
我怎样才能运行这些服务并且仍然有一个结束的 ssh 会话?
更新:我现在手动否认这些过程。这东西还是没有退出。跆拳道队友?
更新:逐行执行时,两个命令不会在不点击 CR 的情况下返回 shell:
nohup bin/zookeeper-server-start.sh config/zookeeper.properties &
nohup bin/kafka-server-start.sh config/server.properties &
Run Code Online (Sandbox Code Playgroud)
小智 24
通常,如果后台连接仍然打开,SSH 终端会话就会挂起。通过后台连接,我的意思是诸如:
通过输入~#
挂起的 SSH 终端,查看挂起的 SSH 会话中仍处于活动状态的连接。
可能是您的脚本正在打开您没有意识到的会话。或者您的远程机器的终端配置.profile
(或.bashrc
等)可能包含建立会话的内容。祝你打猎好运!
顺便说一下,OpenSSH 客户端提供的一些其他转义序列也可能有用:
Supported escape sequences:
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
Run Code Online (Sandbox Code Playgroud)
还有一件事,如果你希望你的SSH只是运行你的命令,并立即退出-也就是说,你不想远程终端会话-您可以使用该-f
选项ssh
。这将强制 SSH 连接成为后台作业。