【问题标题】:SSH command gets hungSSH 命令挂起
【发布时间】:2016-02-11 12:43:35
【问题描述】:

我在远程系统上执行的 while 循环中有 SSH 命令。而且我看到它执行的次数越多,它被挂起的机会就越高。谁能告诉我是否有任何 SSH 配置或选项可以防止这种情况发生。

 if [ -n "${services}" ]
 then
       while [ $flag -eq 1 ]
       do
          for list in $services
          do
            outcome=`ssh $user@$remoteserver "svcs $list" | tail -1 | awk '{print $1}'`
            if [ $outcome != "online" ]
            then
                 flag=1
                 break
            else
                 flag=0
            fi
          done
       done
else
       echo "Failed to get remoteserver list" 
fi

【问题讨论】:

  • 感谢您的回复罗伯特。附上代码。当一个进程不在线时,代码会尝试 ssh 直到它在线。所以它会以这种方式多次 ssh 并导致它挂起。
  • Leo,感谢您的回复。我尝试了 maxstartups 但没有帮助。
  • $services的值是多少?
  • 另外,你可以使用break 2同时退出for循环和while循环——不需要flag

标签: unix ssh freeze


【解决方案1】:

问题在于 ssh 命令从标准输入读取,这会将输入排到您的 while 循环中。

将 ssh 命令更改为 ssh -n 命令。也就是说,将“-n”选项添加到您的 ssh 命令中。

【讨论】:

    猜你喜欢
    • 2011-05-27
    • 2012-01-25
    • 2011-03-22
    • 1970-01-01
    • 2022-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    相关资源
    最近更新 更多