Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a test that I can use in a shell script to test if a remote mount specified in /etc/fstab has been completed? Better yet, is there a test that will tell me if all mounts have been completed without referring to each of them explicitly?
I'm trying to construct a script that will keep retrying a mount until it is accomplished and then go away.
You could test to see if a particular file on the mounted device is present at the mountpoint.
If it's there, the device is mounted. If it's not, it isn't (or someone has deleted the file).
-Or-
mount tells you what is mounted where, and how.
So you could grep the output of mount and test if a particular device is mounted:
Code:
foo=$(mount | grep mountpoint)
if [ "$foo" != "" ] ; then
echo "Mounted"
else
echo "Not mounted yet"
fi
-Or-
This is linux, so there will be other, possibly more "elegant" ways.
It would be nice if there was something I could put into /etc/rc.local that would keep retrying the mounts until they all succeeded but was independent of the particular contents of /etc/fstab. I suppose I could construct a program that examines /etc/fstab and, for each item mentioning cifs or nfs, tests if it is mounted. But that would be a fair amount of work and might be overkill.
I wish there was a form of the mount command that keeps trying the mount until it succeeds, but there doesn't seem to be, particularly for cifs.
The loop will only end when mount succeeds. Of course, change that mount command by your own one, and change the 6 seconds period for whatever you wish.
I think there's a problem with this if the mount has succeeded before the script gets executed. In that case you'll get a duplicate mount, which Linux seems to allow.
It also has to be customized for each nfs/cifs entry in fstab and modified whenever the set of remote mounts changes. It's easy to forget to do that when changing fstab. Perhaps an awk program should be used to scan fstab and extract a list of filenames.
Perhaps there just isn't a purely passive way of checking for mountedness.
The easiest way to see if something's been mounted is to check /etc/mtab.
Not the easiest to automate, but the most reliable, I'd agree. I wish there was a variant of the mount command that would produce a condition code for mountedness, but there doesn't seem to be.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.