簡體   English   中英

使用paramiko通過SSH在交互式CLI上執行命令

[英]executing commands on interactive CLI using paramiko over SSH

我正在使用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

此代碼應執行一些命令(作為字符串傳遞),然后解析通道的輸出。
當我用簡單的shell命令調用這個方法時,我會根據需要獲得輸出。
[例如: print(self.ssh.exec_and_get_remote_output("ls")) ]

現在,當我嘗試在此服務器shell中運行一些CLI進程時,我的問題會調用,該進程應從shell(用戶輸入)獲取輸入並將輸出返回到shell(在屏幕上打印),在這種情況下,chan.exec_command正在返回me None (NoneType )而不是[stdin,stdout,stderr] tuple和raw_output變量(來自通道的輸出)是alsor返回為None ,因此最終沒有打印任何內容,而且,我沒有得到任何異常拋出SshException以便我知道執行此命令是成功的。
這很奇怪,因為當我以交互方式(手動連接到服務器)並運行連接到shell的命令時,所有內容都在終端上打印正常。
[例如: 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)

exec_command兩個不同的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM