This shell script will test each mountpoint and send mail to root if any of them is not mounted:
#!/bin/bash
while sleep 10m;
do
status=$(for mnt in /mnt/disk1 /mnt/disk2 /mnt/disk3; do mountpoint -q "$mnt" || echo "$mnt missing"; done)
[ "$status" ] && echo "$status" | mail root -s "Missing mount"
done
My intention here is not to give a complete turn-key solution but, instead, to give you a starting point for your research.
To make this fit your precise needs, you will need to learn about bash and shell scripts, cron jobs, and other of Unix's very useful tools.
How it works
#!/bin/bash
This announces that this is a bash script.
while sleep 10m; do
This repeats the commands in the loop once every 10 minutes.
status=$(for mnt in /mnt/disk1 /mnt/disk2 /mnt/disk3; do mountpoint -q "$mnt" || echo "$mnt missing"; done)
This cycles through mount points /mnt/disk1
, /mnt/disk2
, and /mnt/disk3
and tests that each one is mounted. If it isn't, a message is created and stored in the shell variable status
.
You will want to replace /mnt/disk1 /mnt/disk2 /mnt/disk3
with your list of mount points, whatever they are.
This uses the command mountpoint
which is standard on modern linux versions. It is part of the util-linux
package. It might be missing on old installations.
[ "$status" ] && echo "$status" | mail root -s "Missing mount"
If status
contains any messages, they will be mailed to root with the subject line Missing mount
.
There are a few different versions of the mail
command. You may need to adjust the argument list to work with the version on your system.
done
This marks the end of the while
loop.
Notes
The above script uses a while
loop that runs the tests every ten minutes. If you are familiar with the cron
system, you may want to use that to run the commands every 10 minutes instead of the while
loop.