finding NFS dirs in csh?

ECSC68 S Brown CS simon at its63b.ed.ac.uk
Fri Dec 5 01:19:31 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 / ..."
>
>
>(Like wow - these transparent file systems are *really* transparent!) 

Well, I havn't found this to be the case at all! (At least using
NFS between SUNs and a Pyramid).
It seems that if you open(2) a remote directory for reading, any read(2)
will return 0 bytes - it looks like a totally empty directory! - there isn't
even "." or ".." entries.
You have to use the getdirentries(2) call to actually read remote directories.

So, you could check if a file is remote by:
     1.	If its a directory (stat => st_mode&S_IFDIR), then try to read
	something from it. If it looks empty then it's remote.
     2.	If its a non-directory, just apply step 1 to its parent.

Of course, it might be a bit more tricky to do things like this in
a shell script... Perhaps something like:

	#
	#	shell function to see if a file is remote
	#
	isremote(){
		if [ -d $1 ]
		then	if [ `cat $1 | wc -c` == 0 ]	# it looks empty
			then return 0			#  true
			else return 1			#  false
			fi
		elif isremote $1/..			# is parent remote?
		then	return 0
		else	return 1
		fi
	}

Of course, this might just only work 'cos NFS is set up wrong here. :-)

--
Simon Brown
Department of Computer Science, University of Edinburgh, Scotland.
...!{decvax,ihnp4,seismo}!mcvax!ukc!cstvax(!its63b)!simon

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Life is full of woe, don't you know..." [Anon.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.unix.questions mailing list