Thursday, March 16, 2023
HomeSoftware EngineeringFind out how to Verify if a Quantity is Mounted in Bash

Find out how to Verify if a Quantity is Mounted in Bash


If it’s worthwhile to verify if a quantity is mounted in a Bash script, then you are able to do the next.

Find out how to Verify Mounted Volumes

First we have to decide the command that can have the ability to verify.

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

Find out how 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

Find out how to Verify 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 obtainable."
else
    echo "It is not obtainable."
fi

One other method 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