【问题标题】:How to get mounted nfs device from a path in Python如何从 Python 中的路径获取挂载的 nfs 设备
【发布时间】:2016-05-09 13:38:01
【问题描述】:

如何从 Python 中的文件路径中找到 nfs 共享的主机?

例如,如果df -h 给出:

Filesystem              Size  Used Avail Use% Mounted on
/dev/sdb3               500G  200G  300G  40% /
hostname:/local           1T   20G  980G   2% /mnt/drive

如果给定/mnt/drive/file.txt,我怎样才能得到“hostname”?

【问题讨论】:

    标签: python nfs


    【解决方案1】:

    可以从mount -l的输出解析挂载点:

    #!/usr/bin/env python
    
    import subprocess
    
    mounts = {}    
    for line in subprocess.check_output(['mount', '-l']).split('\n'):
        parts = line.split(' ')
        if len(parts) > 2:
            mounts[parts[2]] = parts[0]
    
    print(mounts)
    

    然后可以将路径与mounts字典中的键进行比较,并进一步解析值以获得挂载点。

    来源:https://askubuntu.com/a/189990/124703

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      • 1970-01-01
      • 2016-02-04
      • 2013-11-12
      相关资源
      最近更新 更多