Page 1 of 1

Smartmon Disk Check

Posted: Thu Dec 20, 2012 1:29 pm
by Shivaramakrishnan
Hello
I have a smartmon disk check that is working well ,It gives the required result.But the problem I am facing is the exit status.
Here is my script.I have 2 physical drives to which I am performing the test,I need to get notified when a drive fails.
though the script is executing,the exit status seems to be not working.

#!/bin/bash
ok='0'
warning='1'
critical='2'
unknown='3'

#smart='/usr/sbin/smartctl'
string1check=` sudo /usr/sbin/smartctl -H /dev/sda |grep -i PASSED`
string2check=` sudo /usr/sbin/smartctl -H /dev/sdb |grep -i PASSED`

string2catch='SMART overall-health self-assessment test result: PASSED'

if [ "$string2catch" = "$string1check" ]; then
echo 'OK : Drive 1 Good'
$status1=$ok
else
echo 'CRITICAL: Drive 1 Bad'
$status1=$critical
fi

if [ "$string2catch" = "$string2check" ]; then
echo 'OK : Drive 2 Good'
$status2=$ok
else
echo 'CRITICAL: Drive 2 Bad'
$status2=$critical
fi
exit $status1
exit $status2


Current Output :
OK : Drive 1 Good
./check_smart-test: line 15: =0: command not found
OK : Drive 2 Good
./check_smart-test: line 23: =0: command not found

Any help would be greatly appreciated.

Re: Smartmon Disk Check

Posted: Thu Dec 20, 2012 3:24 pm
by sreinhardt
I would suggest changing

Code: Select all

if [ "$string2catch" = "$string1check" ]; then
echo 'OK : Drive 1 Good'
$status1=$ok
else
echo 'CRITICAL: Drive 1 Bad'
$status1=$critical
fi

if [ "$string2catch" = "$string2check" ]; then
echo 'OK : Drive 2 Good'
$status2=$ok
else
echo 'CRITICAL: Drive 2 Bad'
$status2=$critical
fi
To

Code: Select all

if [ "$string2catch" = "$string1check" ]; then
echo 'OK : Drive 1 Good'
status1=$ok
else
echo 'CRITICAL: Drive 1 Bad'
status1=$critical
fi

if [ "$string2catch" = "$string2check" ]; then
echo 'OK : Drive 2 Good'
status2=$ok
else
echo 'CRITICAL: Drive 2 Bad'
status2=$critical
fi
All I did was remove the leading $ from variables when you are setting them, so that they will set properly.

Re: Smartmon Disk Check

Posted: Thu Dec 20, 2012 3:52 pm
by Shivaramakrishnan
My bad,I did not notice that.I thought my logic was wrong.

Re: Smartmon Disk Check

Posted: Thu Dec 20, 2012 4:39 pm
by sreinhardt
Not a problem at all, let us know if there are any other issues with it!