【发布时间】:2020-07-21 11:11:15
【问题描述】:
我正在使用以下代码通过 SSH 成功执行命令:
import paramiko
hosts = ["192.168.1.156"]
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for host in hosts:
client.connect(host, username='user', password='******')
stdin, stdout, stderr = client.exec_command("df -H")
output = ''.join(stdout.readlines())
Print(output)
但是,一旦我将“df -H”命令换成“smartctl -H disk1”,Python 就没有任何输出。 值得一提的是,我也没有收到任何错误。
当我在终端中运行“smartctl -H disk1”时,它工作正常并给出了我期望的输出,但它只是通过似乎是问题的 Paramiko 命令运行它。
有什么想法吗?
干杯,
乔治
【问题讨论】:
-
“我也没有收到任何错误” – 你的意思是在
stderr上没有输出吗?或者你没有得到任何 Python 错误? + 你见过Command executed with Paramiko does not produce any output吗? -
感谢您的回复,使用不同的命令(例如“df -H”或“mount”)输出工作正常,但一旦使用“smartctl”,就没有输出。感谢您的链接,它实际上不是答案,但该答案中的链接解决了我的问题。
-
没想到这是一回事,谢谢你告诉我。