マウントポイントをfstabと比較する

マウントポイントをfstabと比較する

実行中のシステムのマウントポイントを確認して確認するために、Webから次のサンプルスクリプトをインポートしました。

質問:/etc/fstabコメントアウトされていない既存のマウントポイントを比較して強調したいです。もし彼らはそこにいます。

そして、もし他の解決策があるかどうか見てみたいです!

#!/bin/bash
while read ip;
do
    echo "connecting to $ip";
    ssh root@$ip "until mount | grep -w \"/mnt/data\" >/dev/null;
     do echo mounting \"/mnt/data\"; mount \"/mnt/data\"; sleep 1; done && 
     echo Mounted on $ip"
done < ips.txt

ベストアンサー1

これはトリックを行うようです

#!/bin/bash
mountpoints=( $(awk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}' /etc/fstab) )
for mount in ${mountpoints[@]}; do
   if ! findmnt "$mount" &> /dev/null; then
      echo "$mount is declared in fstab but not mounted"
   fi
done

おすすめ記事