我正在开发两台服务器之间的会话多路复用。我想在创建新的服务器(或IP)之前关闭该服务器(或IP)的所有现有套接字,并在完成任务后关闭新创建的套接字。这就是我到目前为止所做的:
remote_ip=192.168.20.2 #User inut
remote_port=222可以通过以下方式创建套接字:
SSHSOCKET=~/.ssh/remote_$remote_ip
ssh -M -f -N -o ControlPath=$SSHSOCKET $remote_ip -p $remote_port可以通过以下方式搜索控制路径:
ps x | grep $remote_ip | grep ssh | cut -d '=' -f 2
/root/.ssh/remote_192.168.20.2 192.168.20.2 -p 222可以通过以下方式关闭套接字:
ssh -S /root/.ssh/remote_192.168.20.2 192.168.20.2 -p 64555 -O exit尝试通过以下方式关闭套接字:
ps x | grep $remote_ip | grep ssh | cut -d '=' -f 2 | xargs ssh -S | xargs -i {} "-O exit"但我得到了:
Pseudo-terminal will not be allocated because stdin is not a terminal.尝试使用-t和-tt:
ps x | grep $remote_ip | grep ssh | cut -d '=' -f 2 | xargs ssh -Stt | xargs -i {} "-O exit"
ssh: Could not resolve hostname /root/.ssh/remote_192.168.20.2: Name or service not known
xargs: ssh: exited with status 255; aborting有谁能帮我一下吗?
发布于 2017-09-20 07:00:27
如果您想要终止从您的机器到给定远程IP地址和端口的每个连接,您可以执行以下操作(使用fuser,这是所有主要的Linux发行版附带的psmisc包中的一个工具):
fuser -k -n tcp ",${remote_ip},${remote_port}"https://stackoverflow.com/questions/46310690
复制相似问题