简体   繁体   English

通过SSH向设备发送多个命令

[英]Sending Multiple Commands to device Through SSH

I am attempting to send multiple commands to a device using the SSHJ library. 我正在尝试使用SSHJ库将多个命令发送到设备。 There is the option of sending multiple commands in this format: 可以使用以下格式发送多个命令:

Command command = sshSession.exec("show line; show ip interface brief;");

This works, but it is not always usable in my case. 这可行,但就我而言并非总是可用。 I have found other suggestions such as the second answer here . 我发现了其他建议,例如第二个答案在这里

When I attempt this suggestion the first command works fine and then it cycles between this error: 当我尝试此建议时,第一个命令运行正常,然后在此错误之间循环:

net.schmizz.sshj.connection.ConnectionException: Broken transport; encountered EOF
...
Caused by: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF

or 要么

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)

The code used is: 使用的代码是:

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

A note if needed, the device I am connecting to, and majority of devices that it will connect to are Cisco networking equipment. 如果需要的话,我要连接的设备以​​及将要连接的大多数设备都是Cisco网络设备。

Thank you for any assistance. 感谢您的协助。 -Jarrod -贾罗德

Never found a resolution for the exact problem. 从未找到确切问题的解决方案。 But I worked around the issue by using the DefaultPTY and providing my own streams with all the data I wanted to send. 但是我通过使用DefaultPTY并为我自己的流提供了要发送的所有数据来解决此问题。 Playing around with this example. 这个例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM