How do I detect that a jump drive is mounted?
Cameron Hutchison
lists at xdna.net
Sat Aug 29 05:43:14 UTC 2009
Knute Johnson <knute2009 at knutejohnson.com> writes:
>I've got a jump drive that I use to back up some files at night. Is
>there a simple way in a script that I can check to see that the drive is
>mounted?
The file /etc/mtab contains a list of the mounted filesystems. This is
maintained by the mount(8) command. This is the traditional Unix file
containing the mounted filesystems.
The file /proc/mounts also contains a list of the mounted filesystems,
but as the kernel knows it, so it is probably more comprehensive than
/etc/mtab. This is a Linux-specific file.
Using grep over either of these should tell you what you want to know.
If your jump drive is mounted on /media/backup then you could use
something like this:
if ! grep -qs " /media/backup " /proc/mounts ; then
echo "Jump drive not mounted" >&2
exit 1
fi
in your script should ensure that there is something mounted on your
backup mount point.
Note the spaces around the mount point - this ensures you dont match
something like /foo/media/backup, or /media/backup/foo.
More information about the ubuntu-users
mailing list