#!/bin/sh ######################################## # Description: This script is used to check the status of the Adaptec 2610SA # RAID controller card and send email notifications on server.test.com. # Required files: id, echo, arcconf, grep, cut, sed, hostname, tr, date, # printf, msmtp, rm # Last modified: July 23, 2010 ######################################## #################### # Set variables #################### id=/usr/bin/id echo=/bin/echo temp_dir=/tmp arcconf=/usr/StorMan/arcconf grep=/bin/grep cut=/bin/cut sed=/bin/sed hostname=/bin/hostname tr=/usr/bin/tr host_results=`$hostname -s` host=`$echo $host_results | $tr '[:upper:]' '[:lower:]'` date=/bin/date current_day=`$date +%m/%d/%y` current_time=`$date +%H:%M:%S` timestamp="$current_day $current_time" printf=/usr/bin/printf from="Test " recipient="systemalerts@test.com" msmtp=/usr/bin/msmtp msmtp_config=/etc/msmtprc rm=/bin/rm arcconf_logs=Ucli*.log #################### # This function checks the status of the adapter. #################### check_adapter() { adapter_options="GETCONFIG 1 AD" adapter_results=$temp_dir/adapter_results.log $arcconf $adapter_options > $adapter_results adapter_status=`$grep 'Controller Status' $adapter_results | $cut -d : -f 2 | $sed 's/^ *//;s/ *$//'` if [ $adapter_status != "Optimal" ] then body="Controller status is not optimal." subject="System Alert: Adaptec RAID warning (controller) on $host [$timestamp]" $printf "From: $from\nTo: $recipient\nSubject: $subject\n\n$body" | $msmtp --file=$msmtp_config -t fi $rm -f $adapter_results } #################### # This function checks the status of the logical devices or arrays. #################### check_logical_devices() { logical_device_options="GETCONFIG 1 LD" logical_device_results=$temp_dir/logical_device_results.log $arcconf $logical_device_options | $grep -A 12 'Logical device number' > $logical_device_results let logical_device=1 $grep 'Logical device number' $logical_device_results | while read device do logical_device_status=$($grep -A 12 "$device" $logical_device_results | $grep 'Status of logical device' | $cut -d : -f 2 | $sed 's/^ *//;s/ *$//') if [ $logical_device_status != "Optimal" ] then body="Array $logical_device status is not optimal." subject="System Alert: Adaptec RAID warning (array) on $host [$timestamp]" $printf "From: $from\nTo: $recipient\nSubject: $subject\n\n$body" | $msmtp --file=$msmtp_config -t fi let logical_device++ done $rm -f $logical_device_results } #################### # This function checks the status of the physical devices or hard drives. #################### check_physical_devices() { physical_device_options="GETCONFIG 1 PD" physical_device_results=$temp_dir/physical_device_results.log $arcconf $physical_device_options | $grep -A 12 'Device #' > $physical_device_results let physical_device=0 $grep 'Device #' $physical_device_results | while read device do physical_device_status=$($grep -A 12 "$device" $physical_device_results | $grep 'State' | $cut -d : -f 2 | $sed 's/^ *//;s/ *$//') if [ $physical_device_status != "Online" ] then body="Hard drive $physical_device state is not online." subject="System Alert: Adaptec RAID warning (drive) on $host [$timestamp]" $printf "From: $from\nTo: $recipient\nSubject: $subject\n\n$body" | $msmtp --file=$msmtp_config -t fi let physical_device++ done $rm -f $physical_device_results } #################### # This function deletes the temporary files. #################### delete_temp_files() { $rm -f $arcconf_logs } #################### # This is the main part of the script. #################### uid=`$id -u` if [ $uid -ne 0 ] then $echo You must be the root user to run this script. exit 0 else check_adapter check_logical_devices check_physical_devices fi delete_temp_files exit 0