8

In my script, I have several layers of statusing:

  1. remote is available (ping)
  2. remote NFS service is active
  3. remote NFS is exporting a certain directory
  4. remote NFS is mounted (mount)

For (2) and (3), I believe rcpinfo is the best bet. For (2) though, I cannot figure out how to narrow my query to the NFS service without starting a subshell (which is not acceptable for this application). For (3), I'm not sure this information is even available remotely (without sshing in, of course).

I'm working on RHEL 6 and have no access to programs that are not included in the standard distribution.

12

For 3) you probably want to use showmount -e remote_nfs_server which shows if remote_nfs_server has exported anything.

And for 2) if you don't want to use a shubshell and know if the remote server runs NFSv3 or NFSv4 and if TCP or UDP, you could query for that specifically with rpcinfo:
rpcinfo -u remote_nfs_server nfs 3 for NFSv3 via UDP and
rpcinfo -t remote_nfs_server nfs 4 for NFSv4 via TCP

For 4) you may want to look at Check if folder is a mounted remote filesystem


Further information:

  • showmount -r remote will tell me if remote is exporting anything, but is there any way for me to determine if remote:/mnt/dir is being exported without starting a subshell (i.e. a pipeline)? – Sean Allred Dec 30 '14 at 21:17
  • showmount -e remote will tell you if remote has exported anything. showmount -r will only give you an error message as that option doesn't exist. You could try to use shell substring matching to basically grep for a regular expression in the showmount output. Maybe have a look at e.g. stackoverflow.com/questions/12619720/… – doktor5000 Dec 31 '14 at 12:02
  • Or put the other way around, I don't know of any standalone command which can specifically query a remote NFS server for one particular mount, and I don't think that exists. Only other two viable ways would be to query the remote server locally via ssh (although even then there's no reliable way to determine if a given directory is currently exported due to the stateless nature of NFS). Other approach could be to try to mount the NFS export from the client and check for the exit code and then the local mount and its contents. – doktor5000 Dec 31 '14 at 12:16
  • My mistake with the -r option versus -e – that's what I meant :) The 'attempt approach' has been suggested before. I don't particularly like it, but it's looking like a real option. – Sean Allred Dec 31 '14 at 13:16
5

You can use showmount -e <server> for some aspects of #3. When the exports are simple, it would at least suggest that a directory (or perhaps a parent of such a directory) is exported.

# showmount -e server
/export                               (everyone)

For #2, I'm not sure what you're looking for. If you're using NFSv3, you'll be looking for at least mountd and nfs (and in some cases may want to confirm lock managers). You could check for any explicitly with rpcinfo as you say.

# rpcinfo -t server mountd 3
program 100005 version 3 ready and waiting
  • showmount -r remote will tell me if remote is exporting anything, but is there any way for me to determine if remote:/mnt/dir is being exported without starting a subshell (i.e. a pipeline)? – Sean Allred Dec 30 '14 at 21:17
  • That depends on the facilities at your disposal. What is your script written in? Why is starting a separate executable (showmount) less of a problem than starting another shell? – BowlOfRed Dec 30 '14 at 21:20
  • I'm writing my script in Python 2.6 and using the subprocess module. I can set up a pipeline with it, but I'd rather not complicate the design that much. I need to avoid starting a subshell to allow the script to be killed gracefully -- if it is killed, its child processes will be killed, but not the children of the child processes. Thus, the subshell would be killed, but not the processes the subshell spawns. I've also noted rpcinfo can take up to three minutes to return, which is the original basis for the no-subshell thing. It's far too late to change that now, though. – Sean Allred Dec 30 '14 at 21:28
  • Write a separate script that does what you need (like calls showmount, but takes an argument for directory and returns success/failure, and includes a timeout that is reasonable for your purposes), then call that script from your python. – BowlOfRed Dec 30 '14 at 21:34
  • I can promise you it's not as easy as you'd immediately think – when it's locked up so, rpcinfo does not respond to anything but SIGKILL (which is a misattribution – the OS obviously just kills the process). At any rate, that would still start a shell to start rpcinfo – the underlying problem remains. – Sean Allred Dec 30 '14 at 21:58
0

List all pseudo root NFS-V4 export directories

ls /net/ip-addr-nfs-server

Check out my answer in another thread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.