[NTLUG:Discuss] Bash script way to tell if a filesystem is mounted
Leroy Tennison
leroy_tennison at prodigy.net
Sat May 29 16:24:54 CDT 2010
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
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
>
Something about this isn't working for me I have /boot as a mount point
(see below)
mount
/dev/hda5 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext2 (rw)
/dev/hda2 on /Data type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
I do the following as root:
[root at localhost ~]# stat -f --format='%i' /
0
[root at localhost ~]# stat -f --format='%i' /boot
0
[root at localhost ~]# stat -f --format='%i' /boot/grub
0
[root at localhost ~]#
Not only am I seeing a directory and it's parent with the same file
system ID when it is a mount point, both IDs are zero. Just in case
there's something special about / (file system root) I mount a USB stick
@ /media/p1
mount
/dev/hda5 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext2 (rw)
/dev/hda2 on /Data type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sda1 on /media/p1 type vfat (rw)
(I have three directories under media: p1, p2 and p3)
[root at localhost ~]# stat -f --format='%i' /media/p1
0
[root at localhost ~]# stat -f --format='%i' /media/p2
0
[root at localhost ~]# stat -f --format='%i' /media/p3
0
The version of stat on CentOS 5.4 (my host) is 5.97
Any idea what's wrong?
More information about the Discuss
mailing list