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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With