スクリプトを介してファイルシステムがマウントされていることを確認する方法

スクリプトを介してファイルシステムがマウントされていることを確認する方法

私はスクリプトが初めてです...非常に基本的なタスクを実行できますが、今は助けが必要です。

バックアップが必要な場合にのみマウントするローカルファイルシステムがあります。

これから始めましょう。

#!/bin/bash
export MOUNT=/myfilesystem

if grep -qs $MOUNT /proc/mounts; then
  echo "It's mounted."
else
  echo "It's not mounted."; then
  mount $MOUNT;
fi

私が言ったように、私はスクリプトにとって非常に基本的です。mount戻りコードを見ると、コマンドの状態を確認できると聞きました。

RETURN CODES
       mount has the following return codes (the bits can be ORed):
       0      success
       1      incorrect invocation or permissions
       2      system error (out of memory, cannot fork, no more loop devices)
       4      internal mount bug
       8      user interrupt
       16     problems writing or locking /etc/mtab
       32     mount failure
       64     some mount succeeded

どうやって確認するのかわかりません。どのような指示がありますか?

ベストアンサー1

このコマンドは多くのLinuxディストリビューションで利用可能ですmountpoint。ディレクトリがマウントポイントかどうかを確認するために明示的に使用できます。次のように簡単です。

#!/bin/bash    
if mountpoint -q "$1"; then
    echo "$1 is a mountpoint"
else
    echo "$1 is not a mountpoint"
fi

おすすめ記事