#!/bin/bash ### IMPORT ENV VARIABLES ### export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin ### ASSIGN VARIABLES ### MAILFROM=EMAIL@ADDR.COM MAILTO=EMAIL@ADDR.COM SSMTP=/usr/sbin/ssmtp ARCCONF=/usr/StorMan/arcconf HTMLOUT=/tmp/raidcheck-htmlout.$$ ### WRITE RAID STATS TO TMP FILE ### if [ ! -x "${ARCCONF}" ] ; then echo "Error: Unable to execute "${ARCCONF}"" | /usr/bin/logger -t raidcheck -p daemon.err echo "Error: Unable to execute "${ARCCONF}"" else rm -f /tmp/raidcheck* "${ARCCONF}" GETCONFIG 1 LD > /tmp/raidcheck.$$ "${ARCCONF}" GETCONFIG 1 PD >> /tmp/raidcheck.$$ "${ARCCONF}" GETCONFIG 1 AD >> /tmp/raidcheck.$$ RC=$? sed -i 's/^.*Command completed successfully.*$\|^.*Controllers found.*$\|^$//g' /tmp/raidcheck.$$ fi if [ "${RC}" != 0 ] ; then echo "Error: Unsuccessful execution of "${ARCCONF}"" | /usr/bin/logger -t raidcheck -p daemon.err exit 1 fi ### SORT RAID ARRAY DETAILS AND EMAIL ### CSTATUS=$(grep -i "status of logical device" /tmp/raidcheck.$$ | sed 's/^.*: //g') if [ "${CSTATUS}" = Optimal ] ; then exit 1 else ######################## ### BUILD HTML EMAIL ### ######################## cat << EOF > "${HTMLOUT}" To: ${MAILTO} From: ${MAILFROM} Subject: `hostname` - RAID Array ${CSTATUS} Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit MIME-Version: 1.0

EOF sed ':a; s/^\( *\) \([^ ]\)/\1\ \;\2/; t a;/^$/d;s/$/
/g;s/^
//g' /tmp/raidcheck.$$ >> "${HTMLOUT}" ### ADD TABLES FOR SECTION HEADERS ### for i in "Logical device information" "Physical Device information" "Controller information" do sed -i "s/$i
/\n<\/tr>\n\n<\/table>/" "${HTMLOUT}" done for i in "Logical device segment information" "Controller Version Information" "Controller Battery Information" do sed -i "s/$i
/
$i<\/th>\n
\n<\/tr>\n\n<\/table>/" "${HTMLOUT}" done ### TIDY UP HTML ### sed -i 's/^.*---//g;/^
$/d;s/   
$i<\/th>\n
>> "${HTMLOUT}" echo \ >> "${HTMLOUT}" ### SEND EMAIL ### which ssmtp > /dev/null if [ "${RC}" != 0 ] ; then echo "Error: Unable to locate SSMTP" | /usr/bin/logger -t raidcheck -p daemon.err exit 1 else cat "${HTMLOUT}" | "${SSMTP}" "${MAILTO}" exit 0 fi fi