Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NFS Stale Mount Check

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
US
I am currently working on the logic associated with testing for stale NFS mounts in my environment.

However, I am at a lost as to why the loop in my first case condition only gives me the first value from the file being passed then drops back to the menu options. I am aware that the stale variable currently does not check against anything but it should not keep the looping construct from working.



Code:
#!/bin/sh
 
clear
PS3='Select option: '
options=("Stale NFS Clients" "Check Server Stale NFS Mounts" "Quit")
select opt in "${options[@]}"

do
  case $opt in
  "Stale NFS Clients")
  while read line
    do
    ssh root@$line lsof | egrep '/stale/fs|/export/backup' | awk '{print $2;}' | sort -fu | wc -l
    if [ $stale > 0 ]
        then
                   lsof | egrep '/stale/fs|/export/backup' | awk '{print $2;}' | sort -fu 
        else
                    echo "There are no stale NFS mount for $line"
    fi
    done < ExportClients
    ;;
  "Check Server Stale NFS Mounts")
 echo -n "Enter hostname to test for stale NFS mounts: "
 read server
   ssh root@$server lsof | egrep '/stale/fs|/export/backup' | awk '{print $2;}' | sort -fu | wc -l
    if [ $stale > 0 ]
        then
                   lsof | egrep '/stale/fs|/export/backup' | awk '{print $2;}' | sort -fu 
        else
                    echo "There are no stale NFS mount for $server"
    fi
    ;;
   "Quit")
    break
    ;;
    *) echo Invalid Option;;
  esac
done

Thank you for your assistance.



I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 
Issue with this was I forgot about SSH reading STDIN.

This resolved the issue.

while read line
do
ssh root@"$line" "lsof | egrep '/stale/fs|/export/backup' | awk '{print $2;}' | sort -fu | wc -l" </dev/null


I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top