Lsof: Bash命令在连接到远程服务器时没有找到。在终端机上同样的工作也是完美的。
我尝试在python中使用以下三个ssh库:pssh、fabric和paramiko.。
主要的错误是,对于pssh和fabric库,我的大多数命令都可以工作,比如ls、df、kill等,但是lsof命令不起作用。它抛出这个错误'lsof: bash命令未找到‘。如果我使用putty连接到终端并运行相同的命令,Lsof就会运行得很好。
所以,我尝试了paramiko的invoke_shell变体,因为它使用的是shell通道。虽然paramiko的invoke_shell正确地运行lsof命令,但它很耗时。
织物代码:
c = Connection()
result = c.run('lsof /lt')
print(result.stdout.strip())Pssh代码:
from __future__ import print_function
from pssh.clients import ParallelSSHClient
hosts = ['host']
client = ParallelSSHClient(hosts, user='usename', password='pass')
output = client.run_command('lsof /lt | grep deleted ', sudo=True)
for host, host_output in output.items():
for line in host_output.stdout:
print(line)因为我对此很陌生,任何帮助都会很感激。请告诉我什么是最好的办法。
发布于 2019-08-14 09:47:38
谢谢你的评论@larsks。修好了。
我所做的就是:运行-a lsof并从那里复制路径,然后将它添加到我的脚本中。
非常感谢!
https://stackoverflow.com/questions/57476137
复制相似问题