用python查找nfs服务器的名称

时间:2021-01-09 17:40:33

标签: python mount nfs linux-df

我希望找到一种方法来查找特定文件/目录来自 python 的 nfs 服务器的名称,而不是使用外部命令。

这是我目前所拥有的,看起来太脆弱了。首先,shell命令本身:

$ findmnt -Do SOURCE /scratch
SOURCE
scratch_server.example.com:/scratch

蟒蛇内部:

import subprocess, sys
cmd = ['findmnt', '-Do', 'SOURCE', '/scratch']
proc = subprocess.run(cmd, capture_output=True)
server = proc.stdout.decode(sys.stdout.encoding).split('\n')[1].split(':')[0]
print(server)
scratch_server.example.com

有没有更好、更“pythonic”的方式来做到这一点?我只是无法想象这是最佳实践。需要明确的是,我完全不关心执行子流程、超时等的最佳方式。我真的不想在子流程中这样做了。谢谢。

0 个答案:

没有答案
相关问题