If you’ll want to verify if a quantity is mounted in a Bash script, then you are able to do the next.
The way to Verify Mounted Volumes
First we have to decide the command that may have the ability to verify.
This may be completed with the /proc/mounts
path.
The 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 isn't mounted."
fi
The way to Verify if a Quantity is Mounted and Obtainable
MNT_DIR=/mnt/foo
df_result=$(timeout 10 df "$MNT_DIR")
[[ $df_result =~ $MNT_DIR ]]
if [ "$BASH_REMATCH" = "$MNT_DIR" ]
then
echo "It is obtainable."
else
echo "It isn't obtainable."
fi
One other means of Checking Quantity Mounts
mount
| lower -f 3 -d ' '
| grep -q /mnt/foo
&& echo "mounted" || echo "not mounted"