выполнение команд в интерактивном CLI с использованием paramiko over SSH - PullRequest
0 голосов
/ 04 апреля 2019

Я использую пакет paramiko для создания SSH на моем сервере.
Я написал следующий код (часть моего модуля), который должен выполнить некоторую команду и вернуть ее вывод.

def exec_and_get_remote_output(self, cmd, decode=True, splitlines=True, ssh_close=False):
    """
    Execute remote command and return output

    :param cmd: command to execute (string)
    :param decode: perform decoding from binary (bool)
    :param splitlines: perform splitting to get list of lines (bool)
    :param ssh_close: close SSH session after execution (bool)
    :return: command output as sting or list of lines
    """

    if CHECK_NONE(self._client):
        logger.debug('ssh client is None')
        return None

    if not self._opened:
        self.open_connection()

    chan = self._client.get_transport().open_session()
    chan.exec_command(cmd)

    logger.debug('Executed SSH command: {}'.format(cmd))

    raw_output = self.receive_output(chan)

    if decode and splitlines:
        output = self._decode_raw(raw_output)
    elif decode and not splitlines:
        output = self._decode_raw(raw_output, splitlines=False)
    else:
        output = raw_output

    logger.debug('Raw output:\n{}'.format(output))

    # Perform cleanup
    self.cleanup(chan, ssh_close)

    return output

Этот код должен выполнить некоторую команду (переданную в виде строки) и затем проанализировать выходные данные из канала.
Когда я вызываю этот метод с помощью простой команды оболочки, я получаю вывод при необходимости.
[например: print(self.ssh.exec_and_get_remote_output("ls"))]

Теперь моя проблема возникает, когда я пытаюсь запустить какой-либо процесс CLI внутри этой серверной оболочки, который должен получить ввод от оболочки (пользовательский ввод) и вернуть вывод в оболочку (напечатать его на экране), в данном случае chan. exec_command возвращает мне None (NoneType) вместо [stdin,stdout,stderr] кортеж, а переменная raw_output (вывод из канала) также возвращается как None, и, следовательно, в итоге ничего не печатается, более того, я не получаю никаких исключений SshException брошен, чтобы я понял, что выполнение этой команды было успешным.
Это очень странно, потому что, когда я делаю это в интерактивном режиме (подключение вручную к серверу) и запускаю команды, которые подключаются к оболочке, все выводит O.K. на терминале.
[пример: print(self.ssh.get_remote_output("echo -e 'show cable rpd' | /opt/confd/bin/confd_cli --noaaa "))]

Я прочитал руководство пользователя exec_command и не увидел ничего, что могло бы вызвать такое поведение.

Это журнал, который я получаю от регистратора:

DEBUG:paramiko.transport:starting thread (client mode): 0x75a745c0
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.4.2
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u6
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_7.4p1)
DEBUG:paramiko.transport:kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group18-sha512', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1'] server key:['ssh-rsa', 'rsa-sha2-512', 'rsa-sha2-256', 'ecdsa-sha2-nistp256', 'ssh-ed25519'] client encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] server encrypt:['chacha20-poly1305@openssh.com', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com'] client mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: ecdh-sha2-nistp256
DEBUG:paramiko.transport:HostKey agreed: ssh-ed25519
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexNistp256 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-ed25519 host key for [10.40.2.142]:2022: b'c145a1e3b7fc4252387d5930a73cc2c9'
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
DEBUG:framework.ssh_client:SSH connection to 10.40.2.142:2022 is open
DEBUG:framework.ssh_client:This message should appear on the console: 
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:Received global request "hostkeys-00@openssh.com"
DEBUG:paramiko.transport:Rejecting "hostkeys-00@openssh.com" global request from server.
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:framework.ssh_client:Executed SSH command: /opt/confd/bin/confd_cli --noaaa
DEBUG:framework.ssh_client:Attempt #1 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #2 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #3 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #4 to check data in the channel:                                                                                                                                                                                                            
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #5 to check data in the channel:                                                                                                                                                                                                            
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #6 to check data in the channel:                                                                                                                                                                                                            
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #7 to check data in the channel:                                                                                                                                                                                                            
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #8 to check data in the channel:                                                                                                                                                                                                            
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #9 to check data in the channel:                                                                                                                                                                                                            
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #10 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #11 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #12 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #13 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #14 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #15 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #16 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #17 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds                                                                                                                                                                                  
DEBUG:framework.ssh_client:Attempt #18 to check data in the channel:                                                                                                                                                                                                           
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #19 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #20 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #21 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #22 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #23 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #24 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #25 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #26 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #27 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #28 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #29 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #30 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #31 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #32 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #33 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #34 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #35 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #36 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #37 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #38 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #39 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #40 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #41 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #42 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #43 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #44 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #45 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #46 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #47 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #48 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #49 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #50 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #51 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #52 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #53 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #54 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #55 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #56 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #57 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #58 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #59 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #60 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #61 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #62 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #63 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #64 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #65 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #66 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #67 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #68 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #69 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #70 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #71 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #72 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #73 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #74 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #75 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #76 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #77 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #78 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #79 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #80 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #81 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #82 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #83 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #84 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #85 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #86 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #87 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #88 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #89 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #90 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #91 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #92 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #93 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #94 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #95 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #96 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #97 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #98 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #99 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Attempt #100 to check data in the channel:
DEBUG:framework.ssh_client:Data is NOT ready yet to be read from channel. Waiting 0.1 seconds
DEBUG:framework.ssh_client:Data is not ready to be read from channel. All 100 attempts are exhausted
DEBUG:framework.ssh_client:ERROR: Unable to get remote output
DEBUG:framework.ssh_client:Raw output:
None
DEBUG:paramiko.transport:[chan 0] EOF sent (0)

1 Ответ

0 голосов
/ 12 апреля 2019

В paramiko есть две разные exec_command функции. Тот, который вы выполняете, не должен возвращать никакого значения. Используйте paramiko.SSHClient.exec_command, который возвращает (stdin, stdout, stderr).

Подробности ниже:

http://docs.paramiko.org/en/2.4/api/channel.html?highlight=exec_command http://docs.paramiko.org/en/2.4/api/client.html?highlight=exec_command

Строка документация:

>>> help(paramiko.channel.Channel.exec_command)
Help on method exec_command in module paramiko.channel:

exec_command(self, *args, **kwds) unbound paramiko.channel.Channel method
    Execute a command on the server.  If the server allows it, the channel
    will then be directly connected to the stdin, stdout, and stderr of
    the command being executed.

    When the command finishes executing, the channel will be closed and
    can't be reused.  You must open a new channel if you wish to execute
    another command.

    :param str command: a shell command to execute.

    :raises:
        `.SSHException` -- if the request was rejected or the channel was
        closed



>>> help(paramiko.SSHClient.exec_command)
Help on function exec_command in module paramiko.client:

exec_command(self, command, bufsize=-1, timeout=None, get_pty=False, environment=None)
    Execute a command on the SSH server.  A new `.Channel` is opened and
    the requested command is executed.  The command's input and output
    streams are returned as Python ``file``-like objects representing
    stdin, stdout, and stderr.

    :param str command: the command to execute
    :param int bufsize:
        interpreted the same way as by the built-in ``file()`` function in
        Python
    :param int timeout:
        set command's channel timeout. See `.Channel.settimeout`
    :param dict environment:
        a dict of shell environment variables, to be merged into the
        default environment that the remote command executes within.

        .. warning::
            Servers may silently reject some environment variables; see the
            warning in `.Channel.set_environment_variable` for details.

    :return:
        the stdin, stdout, and stderr of the executing command, as a
        3-tuple

    :raises: `.SSHException` -- if the server fails to execute the command
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...