Operating System - Linux
1828451 Members
3908 Online
109978 Solutions
New Discussion

Re: Automate Mount point check

 
johnreid
Contributor

Automate Mount point check

Hi Experts ,

I need your help to get a script which will check eack time the system is rebooted or crashed and recoverd , that scripts has to check is all the mount points are mounted ? If not its has to intimate by sending mail.[Including the NFS mount points]



Thanks in Advance

3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: Automate Mount point check

This is a case of the tail wagging the dog. While what you are asking is certainly "doable" (e.g. scripts in rc to tell you when the machine boots) and scanning /etc/fstab and comparing it to df output for each filesystem, the approach is fundamentally flawed. The real answer is to fix your crashes. I cannot imagine a situation where a machime crashes and reboots itself without my knowledge -- or that others can reboot a box without my knowledge.

It's also not enough to know that all the filesystems mounted correctly at boot, you should be doing those checks on either a continuous or periodic automatic basis so that the special case of a reboot is handled implicitly by your already existing monitoring daemons.
If it ain't broke, I can fix that.
Tim Nelson
Honored Contributor

Re: Automate Mount point check

One way..


awk '/nfs/ {print $2}' /etc/fstab|\
while read list
do
OK=
OK=`mount|awk -v x=$list '$1 == x {print "OK"}'`
if [[ $OK != "OK" ]]
then
if [[ $1 = "MANUAL" ]]
then
echo "$list is NOT mounted.. Now executing mount command !! - `date`"
fi
#echo "$list is NOT mounted.. Now executing mount command !! - `date`"|mailx -m -s "INFO - `hostname` NFS info" ux-admin
mount $list > $LOG 2>&1
:
else
if [[ $1 = "MANUAL" ]]
then
echo "$list - $OK"
fi
:
fi
done
James R. Ferguson
Acclaimed Contributor

Re: Automate Mount point check

Hi:

Hmmmm. A sound running system should not encounter these conditions. If you can't mount filesystems, you have issues that need to be resolved. However, you could construct something like this and if it gives you "warm-fuzzies" you could add it as a run-level-3 'rc' script in '/sbin/init.d':

#!/usr/bin/sh
while read DEV MNTPT X
do
grep -q "${MNTPT}" /etc/mnttab || \
mailx -s "${MNTPT} isn't mounted!" root < /dev/null
done < /etc/fstab

Regards!

...JRF...