#!/bin/sh
#
# This scripts use smartctl to check disk health status.
# Since smartctl can only be run by root, this script
# can only be invoked by root.
#
# This scirpt should be put in system crontab run once a day.

# set -x


# check user
##if [ "$(id -u)" != "0" ] 
##then
##	echo "only super user can run this script"
##	exit 1
##fi

reply_to=ctu@ctutech.com
mail_to=ctu@ctutech.com
hostname=$(hostname)

## send_alarm subject info
send_alarm() {
	/usr/sbin/sendmail -r $reply_to <<!
To: $mail_to
Subject: ($hostname) $1

	$2
!
}

# we first check if FastTrak info is still the same
raid_info_ori=/home/ctu/raid_info
if [ ! -f "$raid_info_ori" ]
then
	send_alarm "WARNING: file /home/ctu/raid_info not found" "by $0"
	exit 0
fi

raid_info_now=/tmp/raid_info
rm -f $raid_info_now
cat /proc/scsi/FastTrak/0 > $raid_info_now

diff -q $raid_info_ori $raid_info_now > /dev/null
if [ "$?" != "0" ]
then
	send_alarm "WARNING: raid status changed" "by $0" 
	exit 0
fi

send_alarm "RAID ok"  "RAID ok"

exit 0


###
### WARNING: running smartctl will crash the server.
###
# now we check smartct
#status=$(/usr/sbin/smartctl -a /dev/sda2 | grep Okay)
#if [ "$status" == "" ]
#then
#	send_alarm "WARNING: smartctl -a /dev/sda2 not ok" "by $0"
#	exit 0
#fi
#
#
#send_alarm "raid ok" "by $0"
#
#exit 0
	


