Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...