Author

Topic: How do I write this grep argument? (Read 2230 times)

sr. member
Activity: 252
Merit: 250
October 06, 2011, 03:56:20 AM
#9
Perhaps you should go to cgminer.

It has control system over fan and engine clock (you can switch them or not) in order to set temperature under fixed target (by default 75C). You can define highest temp to stop mining (def. 85C) and highest temp to keep away (def. 95C).

Give it a try. It's sticked in top ten.
sr. member
Activity: 348
Merit: 251
October 04, 2011, 01:03:17 PM
#8
I actually took out the high temp part and just left in the shutdown part. My room is air conditioned so if the temp is ever up to that then there's something seriously wrong and it should be shut down. My setup would not warrant clocking gpu's down for cooling.

Also I used a little program called sendEmail, it allows you to send email from the command line with minimal setup (very basic). I put all my details into a second script and call it from the first. It will tell me that the temp has exceeded and it's shutting down - just so I'm aware!
sr. member
Activity: 313
Merit: 250
October 03, 2011, 05:33:08 PM
#7


You can start the script with a $ at the end, so it keeps running in the background.

That would be & to background.

Whoops, thanks for noticing that, of course you are right Wink
sr. member
Activity: 313
Merit: 250
October 02, 2011, 09:53:39 PM
#6
I was thinking, oh this is no problem just add one line so it sends an email.
BUT this was a little bit more complicated.

Because if the temp is at the $HIGH warning point, it sleeps 2 seconds and
the goes on again. If I just put a mail command there it sends a mail every
few seconds, probably not so good LOL.

So I made a timestamp and check if it sent mail in the last 5 minutes
(found that here: http://stackoverflow.com/questions/205666/what-is-the-best-way-to-perform-timestamp-comparison-in-bash)

And how to make it send the ok temps every hour? I now made it log the temps
to a file, so you can make a cronjob that mails it to you every hour (/tmp/temp.log).

Also I think this script had a bug, the shutdown stuff never executed because
even if you reach $SHUTDOWN_TEMP, the temp is higher then the $HIGH temp
and so it never went into the else loop. Moved that shutdown stuff at the beginning now,
so it gets checked first.  But I probably created more bugs now haha Cool

You can start the script with a $ at the end, so it keeps running in the background.
Maybe you have a startup script for your miners, then you can just add it at the end.

Code:
#!/bin/sh

CARDS="0 1 2 3 4 5"
HIGH=70
SHUTDOWN_TEMP=85
TDAT="/tmp/temp.dat"
TLOG="/tmp/temp.log"
MAILTO="[email protected]"

while true
do
  for card in $CARDS; do
  # read temp
  TEMP=$(DISPLAY=:0 aticonfig --adapter=$card --odgt |grep 'Sensor'|awk -F\  '{ print $5 }'|cut -d. -f1)
  if [ "$TEMP" -gt "$SHUTDOWN_TEMP" ];
  then
    MSG="GPU$card to hot, shutting down in 30 sek.!"
    echo "$MSG" | wall
    echo "$MSG" | mail -s "warning shutdown temp reached" $MAILTO
    sleep 30
    sudo shutdown -h now
  elif [ "$TEMP" -gt "$HIGH" ];
  then
    MSG="High temp GPU$card: $TEMP > $HIGH"
    echo "$MSG" | tee -a $TDAT | wall
    # build a file with a timestamp to compare if mail was
    # sent in the last 5 minutes. First fill it with 0 if not
    # existant.
    if [ ! -f /tmp/.lastmail ]; then
            echo "0" > /tmp/.lastmail
    fi
    last=$(cat /tmp/.lastmail)
    curr=$(date +%s)
    # check difference
    diff=$(($curr - $last))
    # check if diff is greater than 5 minutes
    if [ "$diff" -gt 300 ]; then
            echo "$MSG" | mail -s "GPU$card high temp warning" $MAILTO
            # write timestamp
            echo "$curr" >/tmp/.lastmail
    else
            echo "not sending mail, waiting to reach time limit."
    fi
    sleep 2
    else
      echo gpu$card temp OK: $TEMP | tee -a $TDAT
      sleep 5
    fi
done
  # end of for loop, move temp file so it can be mailed by cron
  mv $TDAT $TLOG
done


sr. member
Activity: 348
Merit: 251
October 02, 2011, 01:48:00 PM
#5
Hello,

I am not a great scripter, but from your screenshot it looks like you want this for multiple gpus?
If so I think you need to add some for loop. I would do it like that:
Code:
#!/bin/sh

CARDS="0 1 2 3 4 5"
HIGH=70
SHUTDOWN_TEMP=85
export HIGH
export SHUTDOWN_TEMP

while true
do
  for card in $CARDS; do
  # read temp
  TEMP=$(DISPLAY=:0 aticonfig --adapter=$card --odgt |grep 'Sensor'|awk -F\  '{ print $5 }'|cut -d. -f1)

  if [ "$TEMP" -gt "$HIGH" ];
  then
    echo "High temp: $TEMP > $HIGH" | wall
    sleep 2
  else
    if [ "$TEMP" -gt "$SHUTDOWN_TEMP" ];
    then
      echo "To hot, shutting down in 30 sek.!" | wall
      sleep 30
      sudo shutdown -h now
    else
      echo temp OK: $TEMP
      sleep 5
    fi
  fi
done
done

and yeah I think it should be shutdown -h now like the poster above me says Cheesy

Excellent! That works perfectly.

Is it possible to get the script to email me with an update of temps every hour and an email if the temperature exceeds high?

Also how do I set this script to run automatically in the background and how to let me know if it's failed?

Thanks a mill.
sr. member
Activity: 313
Merit: 250
October 01, 2011, 06:26:36 PM
#4
Hello,

I am not a great scripter, but from your screenshot it looks like you want this for multiple gpus?
If so I think you need to add some for loop. I would do it like that:
Code:
#!/bin/sh

CARDS="0 1 2 3 4 5"
HIGH=70
SHUTDOWN_TEMP=85
export HIGH
export SHUTDOWN_TEMP

while true
do
  for card in $CARDS; do
  # read temp
  TEMP=$(DISPLAY=:0 aticonfig --adapter=$card --odgt |grep 'Sensor'|awk -F\  '{ print $5 }'|cut -d. -f1)

  if [ "$TEMP" -gt "$HIGH" ];
  then
    echo "High temp: $TEMP > $HIGH" | wall
    sleep 2
  else
    if [ "$TEMP" -gt "$SHUTDOWN_TEMP" ];
    then
      echo "To hot, shutting down in 30 sek.!" | wall
      sleep 30
      sudo shutdown -h now
    else
      echo temp OK: $TEMP
      sleep 5
    fi
  fi
done
done

and yeah I think it should be shutdown -h now like the poster above me says Cheesy
sr. member
Activity: 348
Merit: 251
October 01, 2011, 05:01:52 PM
#3
Whoops, with f1 at the end I get the below....


[: 31: Illegal number:  74.50
[: 31: Illegal number:  74.50
temp OK: 74.50



If I change the first line to #!/bin/bash
I get this...

./overheat: line 15: [:  74.50 : integer expression expected
./overheat: line 20: [:  74.50 : integer expression expected
temp OK: 74.50


I'm not sure what the difference is between sh and bash though.
sr. member
Activity: 348
Merit: 251
October 01, 2011, 03:27:12 PM
#2
Thanks for your help so far. I am still having an issue though.

When running the below I get
user@system:~$ ./overheat
[: 31: Illegal number:
[: 31: Illegal number:
temp OK:

This is the script with added changes:
#!/bin/sh

HIGH=70
SHUTDOWN_TEMP=85.00
export HIGH
export SHUTDOWN_TEMP


while true
do

  # read temp
  TEMP=`aticonfig --adapter=0 --od-gettemperature |grep Sensor |cut -d '-' -f2|cut -d 'C' -f3`

  if [ "$TEMP" -gt "$HIGH" ];
  then
    echo "High temp: $TEMP > $HIGH" | wall
    sleep 2
  else
    if [ "$TEMP" -gt "$SHUTDOWN_TEMP" ];
    then
      echo "To hot, shutting down in 30 sek.!" | wall
      sleep 30
      sudo shutdown now
    else
      echo temp OK: $TEMP
      sleep 5
    fi
  fi

done

sr. member
Activity: 348
Merit: 251
October 01, 2011, 09:23:44 AM
#1
#!/bin/sh

HIGH=70
SHUTDOWN_TEMP=85
export HIGH
export SHUTDOWN_TEMP

while true
do

  # read temp
  TEMP=`sensors|grep 'CPU Temp'|cut -d+ -f2|cut -d. -f1`

  if [ "$TEMP" -gt "$HIGH" ];
  then
    echo "High temp: $TEMP > $HIGH" | wall
    sleep 2
  else
    if [ "$TEMP" -gt "$SHUTDOWN_TEMP" ];
    then
      echo "To hot, shutting down in 30 sek.!" | wall
      sleep 30
      sudo shutdown now
    else
      echo temp OK: $TEMP
      sleep 5
    fi
  fi

done

Here is the output of my script for the below screenshot...
#!/bin/bash
watch -n 1 aticonfig --adapter=0,1,2,3,4,5 --od-gettemperature

On the bold and underlined row in the temp script below I need to figure out how to get the temps out. Any help greatly appreciated - thanks!




Uploaded with ImageShack.us
Jump to: