NFSマウントに接続されているサーバーで利用可能なソフトリンクディレクトリを一覧表示する方法

NFSマウントに接続されているサーバーで利用可能なソフトリンクディレクトリを一覧表示する方法

私たちのサーバーには多くのディレクトリがあります。これらのディレクトリはソフトリンクで作成され、特定のNFS共有に接続されます。 NFS共有に接続されたソフトリンクディレクトリを一覧表示したいと思います。

次のコマンドを使用してソフトリンクディレクトリを作成し、それをNFSに関連付けます。

client 1 # ln -s /net/rchserver01/data/share2/ /tmp/
client 1 # ln -s /net/rchserver01/data/share1/ /var/
client 1 # ll /tmp/
lrwxrwxrwx 1 root     root  27 Sep 13 11:38 share2 -> /net/rchserver01/data/share2/
client 1 # ll /var/
lrwxrwxrwx 1 root     root  27 Sep 13 11:38 share2 -> /net/rchserver01/data/share1/

ベストアンサー1

与えられた入力例:

find /tmp -lname '/net/*'

より一般的には、findすべてのローカルファイルシステムに移動しますが、各ファイルシステムに滞在するように指示します。

find $(lsblk --list --noheadings --output MOUNTPOINT | grep /) -xdev -lname '/net/*'

より一般的には、上記のようにfindローカルファイルシステムの検索を要求しますが、可能なNFSターゲットのリストを作成します。

readarray -t nfsmounts < <(awk '$3 ~ /^nfs/ { print $2 }' < /proc/mounts)
excludes=()
excludes+=("(")
excludes+=(" -lname ${nfsmounts[0]}")
for((i=1;i < ${#nfsmounts[@]}; i++))
do
  excludes+=( " -o -lname '${nfsmounts[i]}/*'")
done
excludes+=(")")
find $(lsblk --list --noheadings --output MOUNTPOINT | grep /) -xdev ${excludes[@]}

ファイルシステムのスタートリストの別のオプション:/proc/filesystemsを解析してファイルシステムの種類を見つけるいいえ nodev:

find $( for type in $(awk '$1 != "nodev"' /proc/filesystems); do mount -l -t "$type" | awk '{print $3}'; done ) \
  -xdev -lname '/net/*'

おすすめ記事