In a bourne shell script (#!/bin/sh) how can check to see if a remote NFS share is mounted and, if it is not, mount it? I've got an ugly set of cat, greps and ifs using the output of 'mount' at the moment but it doesn't seem to be doing a reliable job.
|
|
If possible, setting up automount ( autofs ) would be the standard way to do this. It might already be in your distribution (comes with CentOS / Redhat default install ). Here is a tutorial. Why use Automount?
|
|||||
|
|
Can you grep |
|||||||||||
|
|
In solaris If your checking that the system where the script is running has a remote filesystem mounted then
*mountcommand could be /usr/sbin/mount /path/to/mount if there is a corresponding entry in the /etc/vfstab or /usr/sbin/mount remotehost:/remote/path /path/to/mount |
||||
|
|
|
Use
(I don't know how widespread or portable |
|||
|
|
|
You may be able to do something with stat. The "device" field will be different across different filesystems. So, assuming you want to see if
|
|||
|
|
|
When it comes down to it, shell programming is about plugging together small discrete tools using pipes to produce some kind of compound utility. A utility that did what you're asking for in a "smart" way wouldn't really match the Unix philosophy. If you want to do it more intelligently, you might want to look at doing this in Perl or Python or C, where you can use the library functions to talk to the portmapper to get information about mounted filesystems as a data structure. You can then intelligently perform the tasks to change the current state to the state you want. |
|||
|
|
|
Just to throw another idea out there, the df command can tell you the mounted filesystem of a directory. If you throw in the
|
|||
|
|
|
A few suggestions:
|
|||
|
|
|
|||||
|
