R – How to check an NFS export’s availablity using Ruby

networkingnfsruby

How can I check if an NFS share on network is online/available/alive using Ruby code (on Linux)?

I have a code like this at the moment:

while !Ping.pingecho('192.168.1.116')
end
`mount -a`
exec 'SOMETHING THAT IS PLACED ON NFS SHARE'

And it doesn't work quite OK, because the remote machine exporting the share don't always have the NFS service ready as soon as it goes online on network. That is; it responds to pings but; I'm unable to mount it unless the NFS service starts.

Best Answer

Run the command

rpcinfo -u 192.168.1.116 nfs 3

and check the return status. This invokes NFS procedure 0 on 192.168.1.116, which essentially is an RPC ping. You should redirect stdout and stderr somewhere, as this command apparently has no quiet mode.