0

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).

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

1 Answer 1

2

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
1
  • "There is no harm in calling mount -a even if everything is already mounted." is the answer I was looking while attempting to have a cron remount an smb share on a flaky network. I'd love to learn more about why it's safe to do, though. May 15, 2023 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .