如何檢查掛載是否為軟NFS

如何檢查掛載是否為軟NFS

我正在尋找一個命令來檢查 nfs 資料夾是否已軟安裝,我的 fstab 是:

10.10.1.3:/home/share3     /home/share3  nfs    soft  0  0

答案1

雖然我可能會使用mount(如中所述瓦利納的回答)我自己認為,man mount我們應該改掉這個習慣:

   The listing.
          The listing mode is maintained for backward compatibility only.

          For more robust and customizable output  use  findmnt(8),  espe‐
          cially  in  your  scripts.

findmnt命令還提供了更多的靈活性 - 例如,您可以直接按來源或目標查找(無需grep),並僅輸出特定於檔案系統的選項。比較:

$ mount -t nfs | grep public
192.168.1.127:/c/public on /mnt/nfs/public type nfs (rw,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.127,mountvers=3,mountport=3097,mountproto=udp,local_lock=none,addr=192.168.1.127)

$ findmnt -nM /mnt/nfs/public  -oFS-OPTIONS
rw,vers=3,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.127,mountvers=3,mountport=3097,mountproto=udp,local_lock=none,addr=192.168.1.127

我認為它(還)沒有提供直接獲取特定選項值的方法,因此greporawk仍然是必要的。

$ findmnt -nM /mnt/nfs/public  -oFS-OPTIONS | grep -qE '\bsoft\b' && echo "soft" || echo "hard"
hard

在你的情況下,這將是

findmnt -nM /home/share3 -oFS-OPTIONS | grep -qE '\bsoft\b' && echo "soft" || echo "hard"

答案2

您可以使用該mount命令顯示所有安裝(或檢視/etc/mtab),使用該grep命令選擇特定安裝,然後使用另一個grep命令檢查soft

mount | grep /home/share3 | grep -q soft
if [[ $? -eq 0 ]] ; then
    echo "/home/share3 is mounted with 'soft'"
else
    echo "/home/share3 is not mounted with 'soft'"
fi

相關內容