0

I'm trying to setup a script that will check the RAID status using the MegaCli command. I have 2 RAID volumes, so my script outputs the state of both volumes. What I'm trying to figure out is how to to loop through the output to check each state.

I execute:

/usr/sbin/MegaCli64 -CfgDsply -aALL -nolog |grep '^State' |awk '{print $3}'

And my output is:

Optimal
Optimal

My current script is:

#!/bin/bash
STATUS=`/usr/sbin/MegaCli64 -CfgDsply -aALL -nolog |grep '^State' |awk '{print $3}'`

if [ "$STATUS" != "Optimal" ]; then
  echo -e "Subject: RAID WARNING @ `hostname`\n\n$STATUS"|/usr/sbin/sendmail [email protected]
fi

Which does not work properly. I'm completely new to bash scripting and the results I've found and tried by googling just don't work either.

Aco Strkalj
  • 71
  • 1
  • 1
  • 3
  • 1
    Have any example outputs for good/"Optimal" and bad? Does MegaCli64 return a different exit code for good & bad? That would be more optimal if it did – Xen2050 Apr 06 '19 at 04:54
  • 1
    Possible duplicate of [Bash: Iterating over lines in a variable](https://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable) – Niayesh Isky Apr 06 '19 at 19:27

0 Answers0