Thursday, May 18, 2023
HomeSoftware EngineeringEasy methods to Test if a Quantity is Mounted in Bash

Easy methods to Test if a Quantity is Mounted in Bash


If you must test if a quantity is mounted in a Bash script, then you are able to do the next.

Easy methods to Test Mounted Volumes

First we have to decide the command that may be capable to test.

This may be finished with the /proc/mounts path.

Easy methods to Test 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

Easy methods to Test if a Quantity is Mounted and Out there

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 isn't accessible."
fi

One other means of Checking Quantity Mounts

mount 
    | lower -f 3 -d ' ' 
    | grep -q /mnt/foo 
  && echo "mounted" || echo "not mounted"
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments