Problem on RHEL

I need to search mounted filesystems and use mount -a if at least one of them will be not mounted (they are defined in /etc/fstab but they are network filesystems so they depends on network condition). The check should be performed frequently in crontab. Is there any command which checks mount output and gives true only when all 3 patterns are found (3 patterns but in mixed order, not specific).

  • Do you need to check for stale file systems too, or only for presence of the mounts in /proc/mounts? – Dani_l Jan 10 '17 at 18:12

No need to check anything. There is no harm in calling mount -a even if everything is already mounted.

Now, if you want to know whether something failed to mount, you can check the return value:

mount -a || echo "ERROR: something failed to mount" >&2

You can even retrieve the error message and do something with it (log, mail, etc.)

err=$(mount -a 2>&1) || echo "Mount failed: '$err'" >&2

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.