finding NFS dirs in csh?

der Mouse mouse at mcgill-vision.UUCP
Tue Dec 9 19:15:56 AEST 1986


In article <772 at gcc-milo.ARPA>, brad at gcc-milo.ARPA (Brad Parker) writes:
> Does anyone know how to tell if a file is "remote" in a csh (or sh) script?

> I need to tell if a directory is a remote mount point or below a remote
> mount point.  I want to exclude remote directories in a script which
> spans the file systems from root (/) - you know... "find / ..."

> Any ideas?

> (Like wow - these transparent file systems are *really* transparent!)

Not transparent enough :-(.

Some versions of find have an option for this:

	find / -fstype nfs -prune ....

Without this, I know of no easy way to tell whether a *file* is remote
or not.  From a shell script, that is.  From a C program, just call
stat() (or lstat()); a remote file will show a major device number of
255 (true of MtXinu 4.3+NFS and SunOS 3.0, presumably of SunOS other
numbers as well).  For a *directory*, things are easier.  NFS breaks
the directory-as-a-file paradigm (one of the reasons I hate NFS), so an
attempt to open() and read() a directory will produce errors.  Since
standard I/O insulates programs from these errors, a remote directory
will look like an empty file to many programs.  For example, you can
use

(Bourne shell)
	if cmp -s suspect-directory /dev/null; then
	  echo suspect-directory is remote
	else
	  echo suspect-directory is local
	fi
(C shell)
	if { cmp -s suspect-directory /dev/null } then
	  echo suspect-directory is remote
	else
	  echo suspect-directory is local
	endif

					der Mouse

USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
Europe: mcvax!decvax!utcsri!mcgill-vision!mouse
ARPAnet: think!mosart!mcgill-vision!mouse at harvard.harvard.edu

[USA NSA food: terrorist, cryptography, DES, drugs, CIA, secret, decode]



More information about the Comp.unix.questions mailing list