#!/bin/bash # Script to check whether a filesystem has been remounted read-only due to # an error. Set up a cron job to run this script as often as you'd # like to check the filesystem status. Requires sendmail (or equivalent) on # the local machine. Contributed by Stian Barmen. # Write the name of the device to be checked dev=/dev/mapper/encryptraid tmp=/root/scripts/raidcheck a=`mount | grep $dev | cut -d " " -f 3` if [ "$a" ] then # This surpresses error missing file on first run! `touch $tmp/.rwcheckmail` # If date has not changed since last mail sendt don't # send a new mail. This ensures max 1 mail pr. day! if [ "`date -I`" != "`cat $tmp/.rwcheckmail`" ] then # If echo 1 to the file system is successful, delete # the .rwtest file. Otherwise send mail to root, # adding the date of the sent mail if successful to # .rwcheckmail file (if mail sending fails this does # not happen!). `echo 1 > $a/.rwtest && rm $a/.rwtest || ( \ echo -e "Subject: RW Check - File system $dev is read only\n\n"\ "RW test on $dev detected that the filesystem is read only,\n"\ "consider checking the status of the mounted file system." \ |sendmail root && date -I > $tmp/.rwcheckmail )` fi else # This surpresses error missing file on first run! `touch $tmp/.rwcheckmail` # If date has not changed since last mail sendt don't # send a new mail. This ensures max 1 mail pr. day! if [ "`date -I`" != "`cat $tmp/.rwcheckmail`" ] then # Send mail to root, adding the date of the sent mail # if successful to .rwcheckmail file (if mail sending # fails this does not happen!). `echo -e "Subject: RW Check - File system $dev if not mounted\n\n"\ "Mount test on $dev detected that the filesystem is not mounted,\n"\ "consider checking the status of the mount or drives." \ | sendmail root && date -I > $tmp/.rwcheckmail` fi fi