Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

mount - find name of nfs server with python

I'm hoping to figure out a way to do find the name of the nfs server a particular file/directory is coming from within python, not using an external command.

Here's what I have so far which seems too brittle. First, the shell command by itself:

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

Inside python:

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

Is there a better and more 'pythonic' way of doing this? I just can't imagine this being best practice. To be clear, I'm not at all concerned about the best way of doing subprocesses, timeouts, or the like. I'm really after not having to do this in a subprocess at all. Thanks.

question from:https://stackoverflow.com/questions/65645685/find-name-of-nfs-server-with-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...