Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a pretty badly ventilated computer whose temperature reaches 100º C in some occasions. The poor thing can't be ventilated any better ("put a bigger fan" is not a suitable solution). When the CPU reaches 100º C, the machine stops "violently" (just shuts down). That machine is running Ubuntu 10.10 with lm-sensors-3 (the installed package is lm-sensors 1:3.1.2-6)

I know what program is causing the issue (a very demanding media player) I could actually stop it for a while without causing major disruptions when the temperature reaches 98º C and boot it again when it reaches... lets say 90º C.

Is that possible to do something like that directly through lm-sensors or do I have to create my own process that checks lm-sensors periodically and "does its things" depending on the temperature?

Thank you in advance.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It depends on what is the output of sensors. If yours is something like mine:

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

then you can use the following script, adapting it accordingly. Besides TEMP_STOP and TEMP_START, you should change the regular expression that filters the line from sensors you want to use. It's the parameter to grep, in the temp function.

#!/bin/bash

TEMP_STOP=98
TEMP_START=90

temp() {
    sensors | grep '^temp1:' | sed -e 's/.*: \+\([+-][0-9.]\+\)°C.*$/0\1/'
}

while true; do
    TEMP=$(temp)
    # keep waiting until temp is too hot
    while [ $(echo "$TEMP < $TEMP_STOP" | bc) = 1 ]; do
        sleep 10
        TEMP=$(temp)
    done

    echo temp $TEMP too hot, stopping.

    # now wait for it to cool down...
    while [ $(echo "$TEMP > $TEMP_START" | bc) = 1 ]; do
        sleep 10
        TEMP=$(temp)
    done

    echo ok now, restarting...
done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.