SSHJ Channel Close перед завершением потока ввода

Библиотека:

  1. SshJ
  2. ExpectIt

По сути, попытка подключиться к BNG через ssh для получения определенных значений. При запуске в 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 будет передан на сервер. Пробовал держать как heatbeat, тоже пока безрезультатно.

0 ответов

Другие вопросы по тегам