This is specific to autofs mounts.
I've found numerous ways to check a traditional mount, some use the /proc/mounts file. I can see my mount is still in that file even when the mount is not currently accessible. i.e. it was accessible, but now device is off or asleep.
These are just some of the methods i tried, which all seem to work for my fstab mounts, but not for my autofs mounts - they simply can't see that the autofs mount is not currently available. Using commands like mount or findmnt seem to hang, and i kill them with CTRL+C.
The ultimate goal is to script a check to see if its alive before continuing the script or exiting as appropriate.
This is an example from one of the URLs that always thinks its available, because the mount is in /proc/mounts, even after the device is turned off:
if grep -qs '/mnt/Backups' /proc/mounts; then echo "Destination reachable. Continuing..." else echo "Destination unreachable. Exiting." exit 1 fi echo "test done"
A different (better?) example in the URLs was using findmnt. But this doesn't completely work either e.g.
if findmnt /mnt/Backups; then echo "Destination reachable. Continuing..." else echo "Destination unreachable. Exiting." exit 1 fi echo "test done"
Findmnt hangs: [UPDATE: I just did some more testing, and this didn't hang this time around - instead it reported as the grep method did - it thought the mount was still alive after i put the server to sleep. But earlier today, it froze]
- If the share was mounted, but isn't now (e.g. the server shuts down sometime after my desktop had a connection to it).
- If the share is mounted - findmnt has no problems (finds mount).
- If the share hasn't been mounted since i booted my desktop (correctly can't find mount).
I found a RedHat reference. Maybe i need to define a more reliable SOURCE? I'm stuck.
UPDATE: I've also tried just checking for a directory:
I looked for a directory i knew did not exist on my desktop (smeghead) and it responded as it should - "Destination unreachable. Exiting".
if [ -d "/home/Derek/Desktop/smeghead/" ]; then echo "Destination reachable. Continuing..." else echo "Destination unreachable. Exiting." exit 1 fi
But if i change the path to /mnt/Backups (when Backups disappears thanks to autofs) then the command freezes and i have to CTRL+C.
So it seems the problem is something about autofs and/or the /mnt location that screws it up?