我有一个运行 ssh 的 bash 脚本来创建一个转发端口,使用如下命令:
ssh -N -i keyfile -L 1000:localhost:22 *remote_ip*
Run Code Online (Sandbox Code Playgroud)
有时候监听端口可能很忙,所以这个命令给出了错误:
channel_setup_fwd_listener: cannot listen to port: 1000
Could not request local forwarding.
Run Code Online (Sandbox Code Playgroud)
但是,ssh 连接保持正常并且 ssh 命令阻塞。发生这种情况时,如何使 ssh 实际上失败,以便我的脚本可以处理它?
不幸的是,我还需要在 Solaris(英特尔)上支持它,并且那里的 ssh 命令不支持 ExitOnForwardFailure 选项 - 在这种情况下有什么想法吗?