Skip to content
Advertisement

loop to test all NFS mount point

this code work very well

mountpoint="/mnt/testnfs"
read -t1 < <(stat -t "$mountpoint" 2>&-)
if [ -z "$REPLY" ] ; then
echo "NFS mount stale. Removing..."
fi

If I try to put it into a loop for :

declare -a nfs_array=( "/mnt/testnfs1" "/mnt/testnfs2/" )

for i in "${nfs_array[@]}"
    do
        read -t1 < <(stat -t "$nfs_array" 2>&-)
        if [ -z "$REPLY" ] ; then
            echo "NFS dead"
        fi 
done

Aim is to test all mounts points, this code test and read only the first entries from nfs_array. If I swapped testnfs1 with testnfs2 this code will test testnfs2 mount point and forget testnfs1 🙁

Advertisement

Answer

In your loop it should be:

read -r -t1 < <(stat -t "$i" 2>&-)

Currently it’s just reading the first array value and $i isn’t used.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement