Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new to scripting and linux, my comp gets too hot sometimes and I want to make a script to detect temp1 and if it's over 65 C, it must put it to sleep. I have a diffuculty at comparing values in the script, I couldn't manage to define figures correctly, would anybody fix it please? Here is my stab at it so far

#!/bin/bash

max=65

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

while true; do

if [[ "$val" > "$max" ]]
              then
                sudo /etc/acpi/sleep.sh force
                        sleep 1
                else sleep 10
        fi

        clear
        sensors
done
share|improve this question

1 Answer 1

I managed to make my own script.

 #!/bin/bash

 while true; do
        val=$(sensors | awk '/temp1/ {print $2}')
        max=$(echo "+75.0")
        if [[ "$val" > "$max" ]]
                then
                        dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
                        sleep 10
                else

                        sleep 10
        fi
        clear
        sensors
 done
 exit 0
share|improve this answer
    
This doesn't work on newer Ubuntu versions. There is no /etc/acpi/sleep.sh on Ubuntu 14.04. –  kasperd Jun 13 at 12:15
    
@kasperd try replacing sudo /etc/acpi/sleep.sh force with dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend –  kenn Jun 13 at 13:36
    
Turns out that isn't what I was looking for anyway. I was looking for a way of putting just one CPU core to sleep, not the entire system. –  kasperd Jun 13 at 15:03
1  
@kasperd you can lower CPU clock frequency to keep your CPU from overheating. github.com/Sepero/temp-throttle –  kenn Jun 13 at 15:45
    
That's useful to know about. Alas, even with both cores throttled to the lowest available speed I can't prevent this machine from turning on the fan. –  kasperd Jun 13 at 16:03

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.