Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine if a directory is a mounted NFS mount point in shellscript

Tags:

I want to write a sh/bash script that can determine whether a particular directory is a mount point for an NFS filesystem.

eg something like

$ mkdir localdir $ mkdir remotedir $ mount host:/share ./remotedir $ classify_dirs.sh  -->  localdir is local  -->  remotedir is an NFS mount point 
like image 654
AndrewR Avatar asked Jan 20 '09 03:01

AndrewR


People also ask

How do you check if directory is NFS mounted?

You can always look at the output of mount. It will list all the mounts on the system. You'll be able to tell if your folder is on one of the mounts based off the folder path.

How do I find the mount point of a directory in Linux?

The findmnt command is a simple command-line utility used to display a list of currently mounted file systems or search for a file system in /etc/fstab, /etc/mtab or /proc/self/mountinfo. 1.

Is a mount point a directory?

A mount point is a directory or file at which a new file system, directory, or file is made accessible. To mount a file system or a directory, the mount point must be a directory; and to mount a file, the mount point must be a file.

What is NFS mount point?

An NFS mount point is required to mount a file system via NFS. In a nonconcurrent resource group, all the nodes in the resource group have been mounted using the NFS file system. The NFS mount point must be outside the directory tree of the local mount point.


1 Answers

This question is effectively a dup of how-can-i-tell-if-a-file-is-on-a-remote-filesystem-with-perl

The short answer is to use the stat command

eg

$ stat -f -L -c %T localdir ext2/ext3 $ stat -f -L -c %T remotedir nfs 

Then a directory is an NFS mount point if its type is 'nfs' and its parent directory isn't.

like image 84
AndrewR Avatar answered Oct 02 '22 13:10

AndrewR