Skip to main content
Added loop.
Source Link
Janka
  • 1.7k
  • 9
  • 10

The following shell script uses the videocore utility vcgencmd measure_temp to get a line like temp=37.4'C. It then does some string magic to isolate the 37 from that string, which is then compared to 35. If it's greatersmaller, it waits a second, then tests the temperature again. If it's 35 or more, $HOT_PID is killed. That PID was set to the program in question, which was started in the background.

#!/bin/sh
/path/to/hot/app &
HOT_PID=$!
while [ $(vcgencmd measure_temp|{ IFS== read DUMMY TEMP ; echo $TEMP ; }|{ IFS=. read INTTEMP DUMMY ; echo $INTTEMP ; }) -gtlt 35 ] &&; do sleep 1 ; done
kill $HOT_PID

Note this fails on applications which fork, because you had to kill all the child processes, too. But you could still use the test line as a base and make a better script. Or simply shutdown now the Pi.

The following shell script uses the videocore utility vcgencmd measure_temp to get a line like temp=37.4'C. It then does some string magic to isolate the 37 from that string, which is then compared to 35. If it's greater, $HOT_PID is killed. That PID was set to the program in question, which was started in the background.

#!/bin/sh
/path/to/hot/app &
HOT_PID=$!
[ $(vcgencmd measure_temp|{ IFS== read DUMMY TEMP ; echo $TEMP ; }|{ IFS=. read INTTEMP DUMMY ; echo $INTTEMP ; }) -gt 35 ] && kill $HOT_PID

Note this fails on applications which fork, because you had to kill all the child processes, too. But you could still use the test line as a base and make a better script. Or simply shutdown now the Pi.

The following shell script uses the videocore utility vcgencmd measure_temp to get a line like temp=37.4'C. It then does some string magic to isolate the 37 from that string, which is then compared to 35. If it's smaller, it waits a second, then tests the temperature again. If it's 35 or more, $HOT_PID is killed. That PID was set to the program in question, which was started in the background.

#!/bin/sh
/path/to/hot/app &
HOT_PID=$!
while [ $(vcgencmd measure_temp|{ IFS== read DUMMY TEMP ; echo $TEMP ; }|{ IFS=. read INTTEMP DUMMY ; echo $INTTEMP ; }) -lt 35 ] ; do sleep 1 ; done
kill $HOT_PID

Note this fails on applications which fork, because you had to kill all the child processes, too. But you could still use the test line as a base and make a better script. Or simply shutdown now the Pi.

Source Link
Janka
  • 1.7k
  • 9
  • 10

The following shell script uses the videocore utility vcgencmd measure_temp to get a line like temp=37.4'C. It then does some string magic to isolate the 37 from that string, which is then compared to 35. If it's greater, $HOT_PID is killed. That PID was set to the program in question, which was started in the background.

#!/bin/sh
/path/to/hot/app &
HOT_PID=$!
[ $(vcgencmd measure_temp|{ IFS== read DUMMY TEMP ; echo $TEMP ; }|{ IFS=. read INTTEMP DUMMY ; echo $INTTEMP ; }) -gt 35 ] && kill $HOT_PID

Note this fails on applications which fork, because you had to kill all the child processes, too. But you could still use the test line as a base and make a better script. Or simply shutdown now the Pi.