python - 您可以使用 Paramiko SSHClientInteraction 通过 SSH 通道/连接发送的命令长度是否有限制?
问题描述
我是 Paramiko 的新手,并且尝试了多种方法来完成一项非常基本的任务。此时,我要做的就是在 APC UPS 上执行命令。在我的测试中,我发现我可以成功执行一个命令,只要命令的长度不超过 20 个字符。
这是我的代码 -
import paramiko
from paramiko_expect import SSHClientInteraction
host = "xxx.xxx.xxx.xxx" # UPS
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username='e164468', password='********', banner_timeout=60)
chan = SSHClientInteraction(ssh, timeout=2, display=True)
prompt = 'apc>'
command = 'cipher -rsake disable'
chan.expect(prompt)
chan.send(command)
chan.expect(prompt)
output_raw = chan.current_output_clean
chan.close()
ssh.close()
print ("Here is your output - ")
print(output_raw)
我需要远程执行的命令是'cipher -rsake disable'。当我运行它时,我在终端中得到的是 -
apc>cipher -rsake disablEXCESS TIME RECV_READY TIMEOUT, did you expect() before a send()
如果我从命令中删除 disable 参数,它会按预期工作。无论我尝试了什么,只要命令超过 20 个字符,我都会得到这种行为。
我不确定测试的有效性,但我手动 ssh 到 UPS,可以输入我需要的任何命令,它可以工作。
任何帮助将不胜感激!
解决方案
推荐阅读
- c# - Opencover 分支百分比始终为 0
- python - 使用变量名访问字典
- csv - 如何通过 Go 检查 CSV 文件的字符编码?
- amazon-web-services - 使用 terraform 创建时无法访问 RDS
- reactjs - 使用 useEffect() 和 setTimeOut() 进行条件渲染
- linux - 为什么 pthread_exit 使用 void*?
- javascript - 如何调度 Vue 计算属性
- keras - 多输入输出CNN
- node-modules - 重新导出具有更改类型定义的所有导入
- google-cloud-platform - 从 Spanner 读取数据到 PubSub 队列的最佳方法是什么?