Server Temperature Monitor?
joseph at thatworks.com
Mon Feb 2 16:05:57 MST 2009
On Mon, Feb 2, 2009 at 3:45 PM, Kimball Larsen
<kimball at kimballlarsen.com> wrote:
> Thanks for the ugly one-liner. :)
> In attempting to understand what it does, I have pulled it apart to run it a
> piece at a time. I find the following:
> /etc# TEMP=$(sensors -f | grep -m 1 F); echo $TEMP
> Core0 Temp: +82.4°F
> /etc# TEMP=$(sensors -f | grep -m 1 F); TEMP=$(echo $TEMP | sed
> 's/[^[:digit:]]//g'); echo $TEMP;
> Looks like it is taking the +82.4°F and making it become 0824, which is
> always > 160. So, what is it, exactly, that the magical sed is doing, and
> how can I get it to convert the value correctly?
Oog. Decimals. Didn't think about that. Your output is different than
mine, I'm afraid. Assuming your temps are given as whole numbers,
here's what the script does:
# Grab the first line with an F
TEMP=$(sensors -f | grep -m 1 F)
# Kill anything that isn't a digit
TEMP=$(echo "$TEMP" | sed 's/[^[:digit:]]//g')
# Check to see if the resulting digit is =< 160
if [ "$TEMP" -ge 160 ]; then
# Send an email to root, which will never be read
echo 'TOO HOT' | mail root -s 'TOO HOT'
Easy enough if you have whole numbers in your output, but decimals
will throw it off. Adding this line after the grep line will throw
away the decimal point and anything after it.
TEMP=$(echo "$TEMP" | sed 's/\..*//')
But really, I'm going to echo Doran's comment, that Nagios really is
the best tool for monitoring stuff like this.
And add a Jayce^++ for his comment as well.
More information about the PLUG