Lsof:连接到远程服务器时找不到Bash命令。相同的功能在终端上也很完美。
我已经尝试使用以下三个库在SSH中使用ssh: pssh,fabric和paramiko。
主要错误是使用pssh和Fabric库,我的大多数命令都可以运行,例如ls,df,kill等。但是lsof命令不起作用。它将引发此错误“ lsof:bash命令未找到”。如果我使用腻子连接到终端并运行相同的命令,则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)
由于我对此很陌生,因此我们将不胜感激。请让我知道解决此问题的最佳方法。
答案 0 :(得分:0)
感谢@larsks的评论。这样就解决了。
我所做的是: 运行-a lsof类型,然后从那里复制路径,然后将其添加到我的脚本中。
非常感谢!