You are not logged in.

#1 2008-05-23 04:00:48

Gauvenator
Member
Registered: 2008-04-03
Posts: 172

Shutdown Automatically

How can I make my computer shutdown automatically if a sensor from when I run "sensors" exceeds a certain temperature?

Specifically these sensors:

coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +40.0°C  (crit = +85.0°C)                  

coretemp-isa-0001
Adapter: ISA adapter
Core 1:      +39.0°C  (crit = +85.0°C)

I would like the computer to shutdown if they go over 60°C.  Will I need to make some kind of script?  I don't know any code, but I'm willing to learn.

Offline

#2 2008-05-23 06:35:40

pelle.k
Member
From: Åre, Sweden (EU)
Registered: 2006-04-30
Posts: 667

Re: Shutdown Automatically

Well, you may run something like this;

#! /bin/sh

#do this until $string is nonzero length,
#[] is another form of the command test (see "man test")
while [ -z "$string" ]; do

        #fill the string with _only_ the pattern, if it's visible
        #[+] for literal plus, 6 for six, [0-9] for _a_ numeric,
        #so it will match +60 or more...
        #the string will be empty (zero length) if yhe pattern isn't there
        string="$(sensors | grep -o "[+]6[0-9]")"

        #sleep 5 seconds between before starting over again
        sleep 5s

done

#poweroff if the loop is broken
poweroff

You may save this as a script,and execute it in the background with

sh scriptname.sh $

this is nothing that i guarantee will work. see it as a general example of how to do this with bash
I'm sure there are some daemon/applicatio  you can install to do pretty much the same thing though...

Last edited by pelle.k (2008-05-23 06:37:13)


"Your beliefs can be like fences that surround you.
You must first see them or you will not even realize that you are not free, simply because you will not see beyond the fences.
They will represent the boundaries of your experience."

SETH / Jane Roberts

Offline

#3 2008-05-23 13:52:51

Gauvenator
Member
Registered: 2008-04-03
Posts: 172

Re: Shutdown Automatically

pelle.k wrote:

Well, you may run something like this;

#! /bin/sh

#do this until $string is nonzero length,
#[] is another form of the command test (see "man test")
while [ -z "$string" ]; do

        #fill the string with _only_ the pattern, if it's visible
        #[+] for literal plus, 6 for six, [0-9] for _a_ numeric,
        #so it will match +60 or more...
        #the string will be empty (zero length) if yhe pattern isn't there
        string="$(sensors | grep -o "[+]6[0-9]")"

        #sleep 5 seconds between before starting over again
        sleep 5s

done

#poweroff if the loop is broken
poweroff

You may save this as a script,and execute it in the background with

sh scriptname.sh $

this is nothing that i guarantee will work. see it as a general example of how to do this with bash
I'm sure there are some daemon/applicatio  you can install to do pretty much the same thing though...

Thanks! big_smile

How would I specify a certain part of the sensors output?  And is poweroff different from shutdown?

Offline

#4 2008-05-23 16:39:02

pelle.k
Member
From: Åre, Sweden (EU)
Registered: 2006-04-30
Posts: 667

Re: Shutdown Automatically

How would I specify a certain part of the sensors output?

Eh? I already did that for you? Or do you mean something else?
i instructed grep to cut out *only* the core temps *if* they hits 60-69 degress (6[0-9]), and when that happens you get some output, and it shuts down.

sensors | grep -o "[+]6[0-9]"

Did you mean how to keep the sensors output down to only cpu core temps? I dunno, never used it before.
I guess you could do something like;

sensors | grep "Core [0-9].*(" | grep -o "[+]6[0-9]"

There are multiple ways of doing this, i just took whatever looked comfortable atm.
If you want me to explain exactly what is happening, i'll be happy to do that.


"Your beliefs can be like fences that surround you.
You must first see them or you will not even realize that you are not free, simply because you will not see beyond the fences.
They will represent the boundaries of your experience."

SETH / Jane Roberts

Offline

#5 2008-05-23 17:21:22

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: Shutdown Automatically

shouldn't you add °C or °F at the end of the string to grep.
Well, it's quite unlikely to have 69V somewhere in a computer but you never know... smile

May I ask you why you put square brackets enclosing the plus symbol?

Last edited by carlocci (2008-05-23 17:22:19)

Offline

#6 2008-05-23 17:57:24

pelle.k
Member
From: Åre, Sweden (EU)
Registered: 2006-04-30
Posts: 667

Re: Shutdown Automatically

I didn't really  put that much time into it. Writing regular expressions is an art form really, and i am certainly not an expert on the subject.
Maybe this would be better? It's more thought out.

#! /bin/sh

#do this until $string is nonzero length
while [ -z "$string" ]; do

        #the string will be zero length if the pattern isn't there
        string="$(sensors coretemp-isa-0000 | grep -o "Core [0-9]:[ /t]*[+][6-9][0-9][.][0-9].C")"
        string=$string"$(sensors coretemp-isa-0001 | grep -o "Core [0-9]:[ /t]*[+][6-9][0-9][.][0-9].C")"

        #sleep 5 seconds between before starting over again
        sleep 5s

done

#poweroff if the loop is broken
poweroff

May I ask you why you put square brackets enclosing the plus symbol?

The asterisk (*), plus sign (+), question mark (?), and left brace ({) are special except when used in a bracket expression. A dot (.) is as well. I was aiming for the *literal* plus sign.

[/edit]i changed the script a bit to target those cpu cores with sensors specifically, and cleaned up the regex syntax a bit[edit]

Last edited by pelle.k (2008-05-23 18:51:17)


"Your beliefs can be like fences that surround you.
You must first see them or you will not even realize that you are not free, simply because you will not see beyond the fences.
They will represent the boundaries of your experience."

SETH / Jane Roberts

Offline

Board footer

Powered by FluxBB