Temperature scripts ....

Discussion and Technical Support for general software applications and utilities including OS related issues.
petercmx
Member
Member
Posts: 20
Joined: January 1st, 2012, 12:12 pm

Re: Temperature scripts ....

Post by petercmx »

Not sure if this is relevant or not but I have noticed that if I run the script from putty I get the message

"Both CPU cores are within limits"

and no error message. The message does not appear on the email copy sent out when running from cron.
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Temperature scripts ....

Post by Ian »

Hi,

Can you copy and paste the script in your next post? Maybe something is awry.

Thanks,

Ian.

EDIT: And do you get that error when either temp has been exceeded or only when it's within limits? And perhaps also run it via putty and send me the output from it?
petercmx
Member
Member
Posts: 20
Joined: January 1st, 2012, 12:12 pm

Re: Temperature scripts ....

Post by petercmx »

Think I found it .... there are two lines commented out in the script in the post on January 12. I did not notice this since one of the lines needs me to edit the email address and the path. I just edited out the # and the script now does not appear to be generating any error.

Testing the script with the shutdown temperature is going to be the next area to explore but a little later ...
petercmx
Member
Member
Posts: 20
Joined: January 1st, 2012, 12:12 pm

Re: Temperature scripts ....

Post by petercmx »

well ... I am wrong again. The reason why the messages stopped was that I did not notice when I rebooted the server that it had stalled when one of the hard drives was not properly detected. Fixed that and the problem is back...

This is the script

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 xxxx@gmail.com </home/peter/scripts/cpumsg.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 ''


This is the message I get in email and that is all that I get

Subject - Cron <root@servername> /home/peter/scripts/CPUTempShutdown.sh 35 45 >/dev/null #Shutdown on overheating CPU (failed)

Message body - /home/peter/scripts/CPUTempShutdown.sh: 30: Syntax error: redirection unexpected
Post Reply