NFS フォルダーがソフトマウントされているかどうかを確認するコマンドを探しています。私の fstab は次のとおりです:
10.10.1.3:/home/share3 /home/share3 nfs soft 0 0
答え1
私はおそらくmount
(walinatorの回答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
特定のオプションの値を直接取得する方法は (まだ) 提供されていないと思うので、そのためには またはgrep
がawk
依然として必要になります。
$ 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