Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.
Moderator: General Moderators
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Tue Jul 29, 2008 3:06 pm
I am trying to write a bash script to check the status of my Raid and email me with status ok or status failed. However, I get an error with my if statements. Any ideas?
Code: Select all
#!/bin/sh
################
################
# Raid checker
################
#
#
SUBJECT="RAID Status"
EMAIL="eddie@jaoudestudios.com"
CURRENTRAID="$(cat /proc/mdstat)"
SAFERAID="Personalities : [raid1] [raid6] [raid5] [raid4]
md0 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
md1 : active raid1 sda3[0] sdb3[1]
155412736 blocks [2/2] [UU]
unused devices: <none>"
if ["$CURRENTRAID" = "$SAFERAID"]; then
# send raid 'ok' email
/bin/mail -s "$SUBJECT" "$EMAIL" "aaaaaaa"
fi
else
# send raid 'failed' email
$(mail eddie@jaoudestudios.com -s "Raid Status:: FAILED"
Raid FAILED
Ctrl-d)
fi
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Jul 29, 2008 4:52 pm
Also, I would advice you to grep for
(F) in /proc/mdstat - this means that a device has failed.
E.g:
Code: Select all
Personalities : [raid1]
read_ahead 1024 sectors
md3 : active raid1 sdb1[1](F) sda1[0]
104320 blocks [2/2] [U_]
md2 : active raid1 sdb2[1](F) sda2[0]
1020032 blocks [2/2] [U_]
md1 : active raid1 sdb3[1](F) sda3[0]
3068288 blocks [2/1] [U_]
md4 : active raid1 sdb4[1](F) sda4[0]
4096448 blocks [2/1] [U_]
unused devices: <none>
Last edited by
VladSun on Tue Jul 29, 2008 5:07 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Tue Jul 29, 2008 4:55 pm
Thanks.
I have the if statement working. The problem was not with the if statement but with windows line breaks, I had to convert them to linux line breaks.
But the issue I am having now is it thinks the 2 strings are not equal. Even if I SAFERAID on multiple lines or on one single line it things they are not equal. But when I echo them out they are exactly the same.
What do you think the reason could be that the string are not equal yet when I print them to the screen they are exactly the same?
Thanks
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Jul 29, 2008 5:04 pm
New lines maybe.
Use grep:
Code: Select all
cat /proc/mdstat | grep "(F)"
if [ $? -eq 0 ] ; then /bin/mail -s "$SUBJECT" "$EMAIL" "Failure"; fi
or even:
Code: Select all
cat /proc/mdstat | grep "(F)" 1>/dev/null && /bin/mail -s "$SUBJECT" "$EMAIL" "Failure"
There are 10 types of people in this world, those who understand binary and those who don't
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Wed Jul 30, 2008 6:14 am
Thanks, thats brilliant.
It seems to hang on sending the email? Like its waiting for something.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Wed Jul 30, 2008 6:18 am
Look at the man page of mail command - parameters that are expected, interactive user input, etc.
PS: Use pipes
E.g.:
Code: Select all
cat /proc/mdstat | mail -s Failure myemail@mail.com
There are 10 types of people in this world, those who understand binary and those who don't
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Sun Aug 03, 2008 2:08 am
Really, it never came up in any of my searches. I will take a look, thanks