SSHJ ライブラリを使用して複数のコマンドをデバイスに送信しようとしています。この形式で複数のコマンドを送信するオプションがあります。
Command command = sshSession.exec("show line; show ip interface brief;");
これは機能しますが、私の場合は常に使用できるとは限りません。2番目の回答hereなどの他の提案を見つけました。
この提案を試みると、最初のコマンドは正常に機能し、次のエラーの間を循環します。
net.schmizz.sshj.connection.ConnectionException: Broken transport; encountered EOF
...
Caused by: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
また
Exception in thread "main" java.lang.IllegalStateException: Not connected
at net.schmizz.sshj.SSHClient.checkConnected(SSHClient.java:713)
at net.schmizz.sshj.SSHClient.startSession(SSHClient.java:651)
使用されるコードは次のとおりです。
sshSession = sshClient.startSession();
Command command = sshSession.exec("sho ip int brie");
System.out.println(IOUtils.readFully(command.getInputStream()));//Just to see the reply while testing
command.join(5, TimeUnit.SECONDS);
sshSession = sshClient.startSession();
Command command2 = sshSession.exec("sho line");
System.out.println(IOUtils.readFully(command2.getInputStream()));//Just to see the reply while testing
必要に応じて、接続先のデバイス、および接続先のデバイスの大部分がシスコのネットワーク機器であることに注意してください。
ご協力ありがとうございます。-ジャロッド