python paramiko exec_command_paramiko.exec_command()未执行,并返回“在CLI中找到额外的参数”。...

I am trying to ssh a server using Paramiko and execute a command. But the paramiko.exec_command() returns with an error.Why is this happening?

This is my Python script:

import paramiko

ssh = paramiko.SSHClient()

ssh.load_system_host_keys()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('10.126.141.132', username='usrm', password='passwd')

stdin, stdout, stderr = ssh.exec_command("show chassis")

print(stdout.readlines())

ssh.close()

When executed it returns with this message:

['Extra params found in CLI, this is not supported, exiting the CLI session:\n']

I am using Python 3.5.2 :: Anaconda 4.1.1 (64-bit) with Paramiko on Windows.

I have tried the commands manually and it is working.

解决方案

Based on your latest comment:

I installed a Cygwin Terminal and SSH'd the server with the command...it came up with the Extra params error. Command I executed: ssh usrm@10.126.141.132 "show chassis", Output: No entry for terminal type "dumb"; using dumb terminal settings. Extra params found in CLI, this is not supported, exiting the CLI session:

it sounds like the usrm account's login shell on the SSH server is not allowed to run commands in the non-interactive way. To solve the problem you have to use invoke_shell() like this:

chan = ssh.invoke_shell()

chan.sendall('show chassis\r')

s = chan.recv(4096)

print s

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值