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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…