how to check if a filesystem is mounted?

Hi,
this is a quite trivial question: in a lot of scripts I test if some removable media is mounted at a specific point in the filesystem. I do this with something like the following:

Code:
mount | grep $MOUNT_POINT | wc -l

and test how many lines I got back. Something smaller is

Code:
mount | grep $MOUNT_POINT

and test the return value of grep. If I want to test that a device is mounted exactly in a mount point I do something like:

Code:
mount | grep $MOUNT_POINT | grep $DEVICE


Is there a smarter way or some utility command to test if a filesystem is mounted in a specific position?
 
hedgehog said:
something like this maybe?
Code:
mount |egrep "$DEVICE.*$MOUNT_POINT"

Despite this is smaller than my method, and therefore more elegant, it is based on the same "engine". I was thinking about a mount option or a command that can do something like:

Code:
mount --check $DEVIVE $MOUNTPOINT

or something alike.
 
You can use df(1) command, giving a path or a device as parameter and checking the return value. For example:

Code:
df / ; echo The return value is $?
Filesystem   1K-blocks     Used    Avail Capacity  Mounted on
/dev/ada0s3a  90822300 18912476 64644040    23%    /
The return value is 0
Code:
df /blah ; echo The return value is $?
df: /blah: No such file or directory
The return value is 1
Code:
df /dev/ada0s3a ; echo The return value is $?
Filesystem   1K-blocks     Used    Avail Capacity  Mounted on
/dev/ada0s3a  90822300 18916248 64640268    23%    /
The return value is 0
Code:
df /dev/ada0s3f ; echo The return value is $?
df: /dev/ada0s3f: No such file or directory
The return value is 1
 
wblock@ said:
Sorry, I don't see it. How is df/grep/mount better than hedgehog's mount/grep from post #2?

You are right, it is not better. But having df to directly report in the exit status if the path is mounted is, in my opinion, better than having to grep the mount command.
 
Back
Top