script to send mail when raid fails
Hi..All,
I have configured RAID1(software raid). And since I am newbie in shell scripting, I need shell script to send mail when any of the raid array get fails. It would be very appreciated if anybody already having the script and post it here. or please help me, how can I cut "[" "]" from the below command's output. The raid status is stored in mdstat file. Code:
[ananth@localhost ~]$ cat mdstat | grep "blocks" | awk '{print $4'} |
First:
You don't need to cat AND grep - grep can read by itself - you just do: Code:
grep "blocks" /proc/mdstat You could try solving it by changing the delimiter twice assuming that "[" and "]" appear only once in the output: Code:
grep "blocks" /proc/mdstat |awk -F[ '{print $2}' |awk -F] '{print $1}' You could perhaps simplify the above by using sed the command rather than dual awks. |
Quote:
|
Thanks MensaWater
Sorry, I think I confused you by grep and print the output from only mdstat file instead /proc/mdstat file. Code:
$grep "blocks" /proc/mdstat |awk -F[ '{print $2}' |awk -F] '{print $1}' Code:
$grep "blocks" /proc/mdstat |awk -F[ '{print $3}' |awk -F] '{print $1}' Code:
$cat RAID Code:
$bash RAID |
Thanks cbtshare,
Code:
$grep "blocks" /proc/mdstat | awk '{print $4'} | sed 's/^.*\(UU\).*$/\1/' |
Quote:
Here is a small script, still I am unable to ignore the errors. Code:
cat check_raid_array Code:
bash check_raid_array |
-ne is a numeric comparison operator. You want the string comparison operator !=
|
Quote:
Code:
#!/bin/bash Code:
[root@localhost ananth]#bash check_raid_array Code:
[root@localhost ananth]# cat mdstat Code:
#!/bin/bash Code:
[root@localhost ananth]# bash check_raid_array |
because the
Quote:
|
Thanks cbtshare,
Since I am newbie in shell scripting I am unable to modify the script with "let". So could you please post the modified script with while loop. |
Assuming the grep awk line does what I think ie return status values like UU, U_ etc, how about something like
Code:
#!/bin/bash not strictly reqd, but nice to have. BTW, here are some good bash links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
chrism01's code does it , try that :)
|
Thank you very much chrism01,
Sorry for the late response. Could you please help me to print failed devices using awk/sed? For example Code:
cat mdstat |
All times are GMT -5. The time now is 03:43 PM. |