A colleague of mine ran into your script. This doesn't avoid a "brute force" approach, but if I may in Bash:
while read _ _ mount _; do
read -t1 < <(stat -t "$mount") || echo "$mount timeout";
done < <(mount -t nfs)
mount
can list NFS mounts directly. read -t
(a shell builtin) can time out a command. stat -t
(terse output) still hangs like an ls
*. ls
yields unnecessary output, risks false positives on huge/slow directory listings, and requires permissions to access - which would also trigger a false positive if it doesn't have them.
while read _ _ mount _; do
read -t1 < <(stat -t "$mount") || lsof -b 2>/dev/null|grep "$mount";
done < <(mount -t nfs)
We're using it with lsof -b
(non-blocking, so it won't hang too) in order to determine the source of the hangs.
Thanks for the pointer!
test -d
(a shell builtin) would work instead of stat
(a standard external) as well, but read -t
returns success only if it doesn't time out and reads a line of input. Since test -d
doesn't use stdout, a (( $? > 128 ))
errorlevel check on it would be necessary - not worth the legibility hit, IMO.