微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SSHJ 通道在完成输入流之前关闭

如何解决SSHJ 通道在完成输入流之前关闭

图书馆:

  1. SshJ
  2. 期待

基本上,尝试通过 ssh 连接到 BNG 以检索某些值。在 Juniper Junos 上运行时有一定的 cmd 写入前关闭 cmd 输入流。

代码片段:

private void setup() throws IOException {
    DefaultConfig defaultConfig = new DefaultConfig();
    defaultConfig.setKeepAliveProvider(KeepAliveProvider.HEARTBEAT);
    ssh = new SSHClient(defaultConfig);
    ssh.addHostkeyverifier(
            (s,i,publicKey) -> true);
    ssh.connect(param.getHost(),param.getPort());
    ssh.authPassword(param.getUsername(),param.getpassword());
    session = ssh.startSession();
    session.allocateDefaultPTY();
    Shell shell = session.startShell();
    expect = new ExpectBuilder()
            .withOutput(shell.getoutputStream())
            .withInputs(shell.getInputStream(),shell.getErrorStream())
            .withEchoInput(System.out)
            .withEchoOutput(System.err)
            .withInputFilters(removeColors(),removeNonPrintable())
            .withExceptionOnFailure()
            .build();
}

然后采样调用

expect.sendLine("set cli screen-length 0");
expect.expect(contains(PROMPT));

String cmd = String.format("show configuration routing-instances | match %s | display set",xxx.123);
expect.sendLine(cmd);

log.info(expect.expect(contains(PROMPT)).getBefore().trim());

从 DEBUG 记录器中,通道在写入流之前关闭

[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 29 down to 2088701
disabling complete-on-space
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 2 down to 2088699

[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 10 down to 2088689
{master}
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 37 down to 2088652
user@host>> [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote  - Consuming by 69 down to 2096791
show configuration routing-instances | match ae13.1304 | display set
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 4 down to 2088648
show[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 14 down to 2088634
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 17 down to 2088617
 configuration[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 1 down to 2088616
 routing-instances[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 101 down to 2088515
user@host>> ...ing-instances |[main] INFO  org.example.device  - show configuration routing-instances
[main] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel  - Sending close
[reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local  - Consuming by 6 down to 2088509
[main] DEBUG net.schmizz.concurrent.Promise  - Awaiting <<chan#0 / close>>
[reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel  - Got chan request for `exit-signal`
[reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel  - Got close
[reader] DEBUG net.schmizz.sshj.connection.ConnectionImpl  - Forgetting `session` channel (#0)
[reader] DEBUG net.schmizz.concurrent.Promise  - Setting <<chan#0 / close>> to `SOME`
[main] INFO  net.schmizz.sshj.transport.TransportImpl  - disconnected - BY_APPLICATION

在将 cmd 传递给服务器之前,感谢任何提示为什么通道关闭。尝试保持热拍,但目前没有结果。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。