The right way to Verify if a Quantity is Mounted in Bash
If it’s good to examine if a quantity is mounted in a Bash script, then you are able to do the next.
The right way to Verify Mounted Volumes#
First we have to decide the command that can have the ability to examine.
This may be completed with the /proc/mounts
path.
The right way to Verify if a Quantity is Mounted in Bash#
if grep -qs '/mnt/foo ' /proc/mounts; then
echo "It is mounted."
else
echo "It is not mounted."
fi
The right way to Verify if a Quantity is Mounted and Accessible#
MNT_DIR=/mnt/foo
df_result=$(timeout 10 df "$MNT_DIR")
[[ $df_result =~ $MNT_DIR ]]
if [ "$BASH_REMATCH" = "$MNT_DIR" ]
then
echo "It is accessible."
else
echo "It is not accessible."
fi
One other manner of Checking Quantity Mounts#
mount
| lower -f 3 -d ' '
| grep -q /mnt/foo
&& echo "mounted" || echo "not mounted"