Help with my if statement (sometimes goes to else?)
Numbers are all specified in 4 decimal numbers, e.g 28.50. Occasionaly the following code will slip into the else section and I've no idea why, the temperature is reported correctly.
at present ok=28.00, warning=29.00 and critical=32.00. I'm getting unknown status at 28.62C. Don't really understand what's wrong with the logic... Perhaps someone could help me, this isn't bash specific so people with knowledge of if statements should get it. Code:
DEV_TMP=`echo $DEV_TMP_DEC | tr -d "."` |
Hi,
Why the complicated rules? Code:
if [ $DEV_TMP -ge $critical ];then |
Quote:
|
Might be more obvious if you use the symbols you know by using the intended tools :)
Code:
if (( DEV_TMP >= critical ));then |
Hi -
I think the problem might be "floating point" vs "integer" comparisons. Check out this article and see if it's applicable to your problem: http://www.linuxjournal.com/content/...oint-math-bash 'Hope that helps .. PSM |
Quote:
|
I'm pretty sure it was this bit:
Code:
$DEV_TMP -lt $warning -a $DEV_TMP -le $ok lets say my warning level is 27.00 and my ok level is 26.00 and the current temperature is 26.50: is 26.50 less than warning and less than ok... no its less than warning and more than ok. The initial post regarding keeping things simple was pretty spot on to be honest :). For some reason I only realise my mistakes once they're posted in forums, hehe. |
All times are GMT -5. The time now is 10:49 AM. |