I have a few NFS mounts that I want to be working at all times. If there is a power outage, sometimes NFS clients come up before the NFS server does, and thus the mounts are not there. I wrote a quick little bash script to fix this utilizing the mountpoint command.
Behold (Change the mountpoint(s) to the one you want to monitor.)
#!/bin/bash
#Simple bash script to check mount points and re-mount them if they're not mounted
#Authored by Nick Jepspon 8/11/2019
### Variables ###
# Changes these to suit your needs
MOUNTPOINTS=(/mnt/1 /mnt/2 /mnt/3) #space separated list of mountpoints to monitor
### End Variables ###
for mount in $MOUNTPOINTS
do
if ! mountpoint -q $mount
then
echo "$mount is not mounted, attempting to mount."
mount $mount
fi
#otherwise do nothing
done
I have this set as a cronjob running every 5 minutes
*/5 * * * */mountcheck.sh
Now the system will continually try to mount the specified folder if it isn’t already mounted.