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

Ralph Green sfreader at sbcglobal.net
Sat May 29 09:28:46 CDT 2010


Patrick,
  That's great.  That is just what I was looking for.  stat is a command
I don't use enough.
Thank you,
Ralph

On Sat, 2010-05-29 at 04:03 -0500, Patrick R. Michaud wrote:
> On Sat, May 29, 2010 at 03:50:42AM -0500, Ralph Green wrote:
> >   More detailed version next.  Let's say I want to know if a filesystem
> > is mounted at /cifs_shares/server2.
> 
> Perhaps:
> 
>     PARENTID=$( stat -f --format='%i' /cifs_shares )
>     FILESYSID=$( stat -f --format='%i' /cifshares/server2 )
>     
>     if [ $PARENTID == $FILESYSID ]
>     then
>       echo "/cifshares/server2 is not mounted"
>     else
>     fi
> 
> "stat -f" means you're asking for filesystem information.
> The '%i' format returns the filesystem identifier for the
> given file/directory.  If a directory and its parent
> have the same filesystem identifier, then that directory
> is not a filesystem mount point.
> 
> Pm




More information about the Discuss mailing list