Page 1 of 2

Temperature scripts ....

Posted: January 6th, 2012, 2:37 pm
by petercmx
I think I have done something bad but I do not know what....

My sensors output is fine (see below) but I am getting emails every time the cron event runs complaining.

From the CPU script I get

/home/user/scripts/CPUTempShutdown.sh: line 49: [: -ge: unary operator expected
/home/user/scripts/CPUTempShutdown.sh: line 59: [: -ge: unary operator expected
/home/user/scripts/CPUTempShutdown.sh: line 49: [: -ge: unary operator expected
/home/user/scripts/CPUTempShutdown.sh: line 59: [: -ge: unary operator expected

from the comments at the top of the script it seems that what is needed is the word 'Core' or edit that to fit the output available from sensors. However, the output I see seems to relate to the motherboard ... Does anyone know how do I get the CPU sensor output?


Code: Select all

acpitz-virtual-0
Adapter: Virtual device
temp1:        +22.0°C  (crit = +127.0°C)

it8718-isa-0e80
Adapter: ISA adapter
in0:          +0.94 V  (min =  +0.00 V, max =  +4.08 V)
in1:          +1.14 V  (min =  +0.00 V, max =  +4.08 V)
in2:          +3.31 V  (min =  +0.00 V, max =  +4.08 V)
+5V:          +3.01 V  (min =  +0.00 V, max =  +4.08 V)
in4:          +2.99 V  (min =  +0.00 V, max =  +4.08 V)
in5:          +1.60 V  (min =  +0.00 V, max =  +4.08 V)
in6:          +1.20 V  (min =  +0.00 V, max =  +4.08 V)
5VSB:         +2.90 V  (min =  +0.00 V, max =  +4.08 V)
Vbat:         +3.18 V 
fan1:        3229 RPM  (min =    0 RPM)
fan2:           0 RPM  (min =    0 RPM)
fan3:           0 RPM  (min =    0 RPM)
temp1:        +22.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermal diode
temp2:        +31.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermal diode
temp3:        +27.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermal diode

nouveau-pci-0100
Adapter: PCI adapter
temp1:        +46.0°C  (high = +100.0°C, crit = +110.0°C)

k10temp-pci-00c3
Adapter: PCI adapter
temp1:        +20.4°C  (high = +70.0°C)

Re: Temperature scripts ....

Posted: January 8th, 2012, 1:47 am
by petercmx
I got some help on ubuntuforums and from that I learn that the CPU temperature is stated, it is the 'k10temp-pci-00c3' section and the temperature is probably understated by 6-8 degrees. I do not know how to edit the script to show that information though. Any ideas?

Re: Temperature scripts ....

Posted: January 8th, 2012, 11:07 am
by Ian
Hi there,

I'll knock a script up for you. I'm off out for the day in a mo but I'll make a start later. :thumbup:

Ian.

Re: Temperature scripts ....

Posted: January 8th, 2012, 11:25 am
by petercmx
magic .... thank you :)

Re: Temperature scripts ....

Posted: January 9th, 2012, 8:57 pm
by Ian
Here you go.

Please give this script a try and let me know how you get on. If it seems to be working then I'll upload another one which is more "finished".

Ian.

EDIT: Forgot to say. Please try with a few different "warning" and "critical" temperatures just to check it's reporting as it should.

Re: Temperature scripts ....

Posted: January 10th, 2012, 7:58 am
by petercmx
Thank you for the file. I will test it later today and give you the feedback :)

Re: Temperature scripts ....

Posted: January 11th, 2012, 3:31 pm
by petercmx
Just to let you know that there is a delay ... fell asleep at the k/b yesterday and hit a problem today. It looks like the file was created with a Windows machine and that has some encoding which is affecting what I see -- the file is all double spaced which means that it does not look right and generates quite a lot of errors when I try to run it. I will try to sort this out in the next day or so but I have to get a few other things out of the way first ...........

Re: Temperature scripts ....

Posted: January 11th, 2012, 5:09 pm
by Ian
Hi,

My goodness, it didn't look like that when I uploaded it :oops:

I'll upload a fresh copy for you. Save you removing all those spaces manually. :thumbup:

Ian.

Re: Temperature scripts ....

Posted: January 11th, 2012, 7:24 pm
by Ian
Try copy and pasting this one instead.

Code: Select all

#!/bin/bash

echo "JOB RUN AT $(date)"
echo "======================================="

echo ''
echo 'CPU Warning Limit set to => '$1
echo 'CPU Shutdown Limit set to => '$2
echo ''
echo ''

sensors

echo ''
echo ''

str=$(sensors)

count=1
foundit=1

while read line
do
    if echo "$line" | grep -q "isa-0001"
    then
      foundit=$count
      break
    fi
    count=$((count+1))
done  <<<"$str"

foundit=$((count+2))
count=1

while read line
do
    if test $count = $foundit
    then
      newstr=${line:16:2}

      if [ ${newstr} -ge $1 ]
      then
        echo '============================'
        echo $(date)
        echo ''
        echo ' WARNING: CPU TEMPERATURE EXCEEDED' $1 '=>' $newstr
        echo ''
        echo '============================'
      fi

      if [ ${newstr} -ge $2 ]
      then
        echo '============================'
        echo $(date)
        echo ''
        echo ' CRITICAL: CPU TEMPERATURE EXCEEDED' $1 '=>' $newstr
        echo ''
        echo '============================'
#        /sbin/shutdown -h now
#        /usr/sbin/ssmtp user@email.com </media/WD1000FYPS/RAIDMain/MyScripts/msg.txt
        echo 'Email Sent.....'
        exit
      else
        echo ' Temperature Core '$i' OK at =>' $newstr
        echo ''
      fi
   fi
   count=$((count+1))
done <<<"$str"

echo 'Both CPU Cores are within limits'
echo ''

Re: Temperature scripts ....

Posted: January 12th, 2012, 1:21 pm
by petercmx
The script appears to be working, thank you :) ... if I take out >/dev/null from the cron command I can see the output on screen.

However ... I am getting an error message when running from cron. It reads

30: Syntax error: redirection unexpected

Have I missed editing something?