[NTLUG:Discuss] Bash script way to tell if a filesystem is mounted

Ralph Green sfreader at sbcglobal.net
Sat May 29 03:50:42 CDT 2010


Howdy,
  I am writing a small bash script and I have one thing that I have not
figured out a nice way to do.  I want to know if a filesystem is mounted
at a particular point.  I can't count on any particular file being there
or even that there are files.  Right now, I parse the output from df to
see if I find it, but I think there out to be a better way.
  More detailed version next.  Let's say I want to know if a filesystem
is mounted at /cifs_shares/server2.
 I can do:
  df > temp_file
  grep server2 temp_file

 I have named my mount points such that the grep won't get any false
positives.

 I bet there is a better way to do this, but I have not found it.  Any
ideas?

 The overall purpose of this script is to check for the filesystem.  If
it is mounted, then just tell the user it is already there and exit.  If
it is not mounted, then run the mount command, which uses sudo to mount
and will prompt the user for the password.  Finally, a check is done to
verify the mount and status is given to the user.  The script will be
available for the user to connect shares from remote computers.  I don't
put them in fstab, because they are not used all the time and the other
computer may not be up when this computer boots.
Good night,
Ralph





More information about the Discuss mailing list