0
我有一個bash腳本,使用ssh來遠程轉發,這樣我就可以登錄運行腳本的機器。我使用腳本,因爲定期網絡需要某種授權。如果ssh失敗,我會重試。該腳本基本上是這樣的:爲什麼不遠程遠程失敗時退出?
while [ 1 ]; do
authentication
ssh -N -v -R 9999:localhost:22 [email protected]$remote_ip
done
問題是ssh將在遙控前進失敗不會退出象下面這樣:
debug1: Remote: Forwarding listen address "localhost" overridden by server GatewayPorts
debug1: remote forward failure for: listen 9999, connect localhost:22
Warning: remote port forwarding failed for listen port 9999
debug1: All remote forwarding requests processed
該故障是由於這樣的:
debug1: server_input_global_request: tcpip-forward listen localhost port 9999
debug1: Local forwarding listening on 0.0.0.0 port 9999.
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 9999
的前一個會話還沒有結束,並且該端口正在使用中。
有沒有辦法檢查ssh是否成功?作爲一名程序員,我真的不明白爲什麼要這樣設計。這個設計背後的基本原理是什麼?