views:

348

answers:

1

I have a procedure I want to initiate only if several tests complete successfully.

One test I need is that all of my NFS mounts are alive and well.

Can I do better than the brute force approach:


mount | sed -n "s/^.* on \(.*\) type nfs .*$/\1/p" | 
while read mount_point ; do 
  timeout 10 ls $mount_point >& /dev/null || echo "stale $mount_point" ; 
done

Here timeout is a utility that will run the command in the background, and will kill it after a given time, if no SIGCHLD was caught prior to the time limit, returning success/fail in the obvious way.


In English: Parse the output of mount, check (bounded by a timeout) every NFS mount point. Optionally (not in the code above) breaking on the first stale mount.

A: 

You could write a C program and check for ESTALE.

Teddy
From `man 3 errno`: ESTALE Reserved. Does this mean I should look for another solution?
Chen Levy
I guess it depends on your kernel.
Teddy
Yes, you are right: In a later version of my distro `man 3 errno` say: "`ESTALE` Stale file handle (POSIX.1)) This error can occur for NFS and for other file systems". And although I went with the brute force approach, described in my question, I will accept this answer.
Chen Levy