how to be alerted if mount status changes

I have a few linux server that i am tyring to setup some alerts for. There is one main Linux server that is connected to a fibre channel SAN that is mounted on the box. these drives are then shared via NFS to the other servers.

Recently we had a few problems where there were some file system errors and the drives changed to read only.

My question is how I can monitor and create an alert if this were to happen again? I am using Opmanager to monitor my network devices and servers, and have configured it to monitor some processes on the Linux serversm, but I cant seem to get it to monitor the status of the mounts.

How can this be accomplished? Do I need to setup a log server or can this be scripted?
LVL 12
ryan80Asked:
Who is Participating?
 
wesly_chenConnect With a Mentor Commented:

1. Create a script
-- /usr/local/bin/check_mount.sh ---
#!/bin/sh

HOSTNAME=`hostname`
NFS_MOUNT=/nfs-mount

touch ${NFS_MOUNT}/test-mount
if [ $? -eq 0 ]
then
   echo "the nfs is rw"
   /bin/rm -f
else
  echo $NFS_MOUNT | mail -s "nfs mount fail on $HOSTNAME"  <ops email address>
fi

2.
chmod +x /usr/local/bin/check_mount.sh

3. setup cron job each NFS client to check every hour
$ crontab -e
1 * * * * * /usr/local/bin/check_mount.sh > /dev/null 2>&1
0
 
ryan80Author Commented:
thank you
0
 
wesly_chenCommented:
Woo, I missing something...
-------  /usr/local/bin/check_mount.sh
..
touch ${NFS_MOUNT}/test-mount
if [ $? -eq 0 ]
then
   echo "the nfs is rw"
   /bin/rm -f ${NFS_MOUNT}/test-mount   #### change this line
else
...
0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
ryan80Author Commented:
i keep on getting this error when running this script:

check_mount.sh: line 7: [: missing `]'
check_mount.sh: line 7: ?: command not found


This is what I have for the script

#//bin/sh

HOSTNAME='rbmpl01'
FIBRE_MOUNT=/Production

touch ${FIBRE_MOUNT}/test-mount
if [ &? -eq 0 ]
then
        echo "the Production mount is rw"
else
        echo $FIBRE_MOUNT | mailx -s "mount fail on $HOSTNAME" ryan.palamara@zaisgroup.com
fi
0
 
ryan80Author Commented:
by the way it is fedora 9 if that matters.
0
 
wesly_chenCommented:
> if [ &? -eq 0 ]
You have typo there
it should be
if [ $? -eq 0 ]
0
 
wesly_chenCommented:
Work for all the Linux

Your first line is wrong
>#//bin/sh
should be
#!/bin/sh
0
 
ryan80Author Commented:
thank you again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.