Bash script to monitor raid

Small bash script I wrote to monitor an Areca RAID card. If the array fails, it sends me an email. It can be used for other RAID cards (such as 3ware), with slight modifications.

How does it work? Basically, the script is executing the manufacturer binary (/usr/areca/V1.82_81103/x86-64/cli64) and simulate the commands I would normally type to get the raid status (vsf info [enter] quit [enter]). Then the script is looking for a specific keyword ("Normal" in that case) when the array is healthy. If that keyword is not found, the script will send an email to the specified address.

BINARY="/usr/areca/V1.82_81103/x86-64/cli64"
EMAIL="yourmail@example.com"
EMAILSUB="Server problem"
EMAILMSG="hard drive failure"
EXPECTED="Normal"
 
MAIL=$(which mail)
GREP=$(which grep)
 
RAIDSTATE=$( $BINARY <<_EOF_
vsf info
quit
_EOF_)
 
echo $RAIDSTATE 2>&1 | $GREP $EXPECTED > /dev/null 2>&1
 
if [ "$?" -ne "0" ]; then
  echo $EMAILMSG | $MAIL -s $EMAILSUB $EMAIL
fi