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.

Recently I've started mining litecoins. My miner consists of 3 Radeon R9 290x GPUs. From time to time one of them (not a specific one, it happens randomly) stops mining. Usually restarting cgminer (mining program) doesn't help, the only thing that helps is reboot. Next week I'm leaving for 8 days and I have nobody to do that for me so I thought of a script that would do that automatically.

The script would have to periodically verify if all GPUs are working and if not - reboot. I think temperature reading is the easiest thing to determine if all cards are working. I know how to read temperature, reboot, add stuff to cron. What I don't is how to put it all together.

Get temperature command:

 aticonfig --odgt --adapter=all | grep Sensor:

Output looks like this:

 Sensor: Temperature - 77.00 C
 Sensor: Temperature - 77.00 C
 Sensor: Temperature - 77.00 C

I would like the script to read the numerical value and reboot if it drops below XX.

Can you please help me out?

share|improve this question
    
I've just noticed that on my PC aticonfig --odgt --adapter=all shows really only temp of GPU0. Three times. When I do aticonfig --adapter=1 --odgt it also shows the temp of GPU0. Even when I do aticonfig --adapter=7 --odgt it keeps returning the temp of GPU0 despite the fact that GPU7 does not exist. –  JazzGott Jan 4 at 22:46

2 Answers 2

up vote 2 down vote accepted

Save this a script and make it executable (chmod +x scriptname.sh) and run it with bash using sudo as reboot requires root.

#! /bin/bash
while :
do
    temp=$(aticonfig --odgt --adapter=all | grep Sensor: | sed 's/[a-zA-Z:-]//g'|  tr -d ' ')

    action=$(echo $temp|awk '{ print ($1 < 76) ? "reboot" : "" }')

    $action
    sleep 1
done

I have not tested it with the ATI command as I don't have access to the command, but it works replacing aticonfig --odgt --adapter=all | grep Sensor: with echo 'Sensor: Temperature - 77.00 C'. This was how I tested it.

The 76 is the restart temp. You can edit that.

share|improve this answer
    
When I change "reboot" to "echo blabla" it just keeps echoing blabla despite having changed the temp to 50 and the real temp being 78. Suggestions? –  JazzGott Jan 4 at 22:52
    
I know. I replaced > with < and it worked. Thanks! –  JazzGott Jan 4 at 22:54
    
I have corrected the > to < now. I didn't read carefully, I assumed you had an overheating problem!! –  Julian Stirling Jan 5 at 9:35

This should do work:

#!/usr/bin/env bash    
while true; do
  aticonfig --odgt --adapter=all | 
   awk var t="$1" '(/Sensor:/ && $(NF-1) < t ){exit(1)}' || reboot 
   sleep 10 
done

Save the script above as gpu_temp.sh, make it executable and run it with the temperature limit you want as an argument:

/path/to/gpu_temp.sh 77

I don't have an ati card so I can't test this but that should cause your machine to reboot if a GPU core falls below 77 °C.


Explanation

  • The while true starts an endless loop, the script will run until killed.
  • The awk line checks if the next to last field (($NF-1)) of lines containing Sensor: is less than whatever you chose and, if so, exits with exit status 1.
  • The command to the right of || will be executed if the command on the left failed, if it exited with non-zero status. So, if one if the cores is below a certain temperature, the awk script will fail and the system will be rebooted.
  • sleep 10 just pauses the script for 10 seconds so you don't flood your system with requests.
share|improve this answer

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.