1

This script worked in the past, then was updated for 14.04.

#!/bin/bash

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

In 16.04 it gives an error:

Error org.freedesktop.DBus.Error.UnknownMethod: No such method 'Suspend'

Can it be updated so it would work in 16.04?

3

I have decided to vote to close this and to radically update the other question, where I expect an answer.


As the error was Error org.freedesktop.DBus.Error.UnknownMethod: No such method 'Suspend', after the comment made by Nick Sillito under this question linking to this answer, I have modified the script in what I expect to be a rather barbaric manner (I'm CL-illiterate myself); I've simply replaced this entire part:

    dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend

with

    systemctl suspend

As indicated in the comment made by wjandreea: sleep 10 or a similar value shouldn't be removed (as I initially did); without that line, the modified script will use more power because instead of running every 10 seconds, it will as fast as possible -- upwards of several dozen times per second.

At this point he system goes to sleep when going above the level set in the line

max="+75.0"

As I want a higher value, 82, the script I use is:

#!/bin/bash

while true; do
   val=$(sensors | awk '/temp1/ {print $2}')
   max="+82.0"
   if [[ "$val" > "$max" ]]; then
                        systemctl suspend

   fi
   sleep 10
   clear
   sensors
done
exit 0
| improve this answer | |
  • 1
    Your modified script uses more power because you removed sleep 10. So instead of running every 10 seconds, it runs as fast as possible -- upwards of several dozen times per second. – wjandrea Jan 27 '17 at 4:20
  • @wjandrea - that's exactly the kind of correction I was asking for! I will try to fix it, after that please take a look and comment again, and if something looks fishy you may also edit my answer. - You should even post under the linked answer and get the bounty, because this looks like an answer. – user47206 Jan 27 '17 at 11:43