我在一段java代码中遇到ssh连接问题。
这是罪魁祸首代码
public class ExecuteSecureShellCommand extends Object {
public static void main(String[] args) throws IOException {
String [] machines = new String[] {machine0, machine1, machine2, machine3, machine4, machine5};
ArrayList<Process> arr = new ArrayList<Process>();
for (int i = 0; i < 1000; i++){
for (String machine : machines){
String[] shell_connector = {"ssh", "-x", "msalem@"+machine, "echo ok"};
Process process=null;
ProcessBuilder builder = new ProcessBuilder(shell_connector);
process = builder.start();
arr.add(process);
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for (Process p: arr){
BufferedReader error_getter = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String error_line = null;
while((error_line = error_getter.readLine()) != null)
System.out.println(error_line);
error_getter.close();
}
}
}
此代码仅用于测试目的,没有任何有意义的结果。但问题是它导致了错误: 远程主机关闭的ssh_exchange_identification连接
供参考:
我想知道这段代码有什么问题? 在不失败的情况下执行大量ssh连接的最佳方法是什么?
事先,为你的答案付出了很多! 问候。