【问题标题】:Unifi's command not found with the paramiko's shell [duplicate]使用 paramiko 的外壳找不到 Unifi 的命令 [重复]
【发布时间】:2020-11-29 19:12:26
【问题描述】:

我想向 Unifi 天线发送 SSH 命令,特别是以下命令:set-inform http://unifi.<ip>:<port>/inform。这个命令在 Putty 中是完全可用的,但是当我使用下面的代码时,我得到了这个响应:

Resp: 
Err: ash: set-inform: not found

我怀疑所选外壳有错误。

import paramiko

ip = 'XX.XX.XX.XX'
port = 22
username = 'XXX'
password = 'XXX'
try:
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, port, username, password)

    stdin, stdout, stderr = ssh.exec_command("set-inform http://unifi.<ip>:<port>/inform")
    outlines = stdout.readlines()
    errors = stderr.readlines()
    resp = ''.join(outlines)
    respErrors = ''.join(errors)
    print('Resp: '+resp)
    print('Err: '+respErrors)# Output
except AttributeError:
    print("Erreur inconnue" + stderr)
except TimeoutError:
    print("Erreur de connexion")

【问题讨论】:

  • 使用set-inform 命令的完整路径,以便您的shell 可以找到它。为了找到完整路径,请使用 Putty 运行which set-inform
  • 命令which set-inform 没有给我任何回报:(。这是来自 Unifi 的特定命令
  • 好的,试试type set-inform

标签: python shell ssh paramiko


【解决方案1】:

我需要指定命令的路径。以下是要写的内容:

stdin, stdout, stderr = ssh.exec_command(" /usr/bin/mca-cli-op set-inform http://unifi.<ip>:<port>/inform")

你可以在这里看到整个项目:https://github.com/simbarras/unifiAdopter

【讨论】:

  • 酷,干得好。感谢您与 Stack Overflow 社区分享。您可以接受自己的答案并获得积分。
猜你喜欢
  • 2011-11-10
  • 1970-01-01
  • 1970-01-01
  • 2015-10-31
  • 2021-03-27
  • 2015-10-19
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多