Code/fan-enable-safe

From ThinkWiki
Jump to: navigation, search
  1. !/bin/sh
  1. july 2005 Erik Groeneveld, erik@cq2.nl
  2. It makes sure the fan is on in case of errors
  3. and only turns it off when all temps are ok.

IBM_ACPI=/proc/acpi/ibm THERMOMETER=$IBM_ACPI/thermal FAN=$IBM_ACPI/fan MAXTRIPPOINT=65 MINTRIPPOINT=60 TRIPPOINT=$MINTRIPPOINT

echo fancontrol: Thermometer: $THERMOMETER, Fan: $FAN echo fancontrol: Current `cat $THERMOMETER` echo fancontrol: Controlling temperatures between $MINTRIPPOINT and $MAXTRIPPOINT degrees.

  1. Make sure the fan is turned on when the script crashes or is killed

trap "echo enable > $FAN; exit 0" HUP KILL INT ABRT STOP QUIT SEGV TERM

while [ 1 ]; do

      command=enable
      temperatures=`sed s/temperatures:// < $THERMOMETER`
      result=
      for temp in $temperatures
      do
              test $temp -le $TRIPPOINT && result=$result.Ok
      done
      if [ "$result" = ".Ok.Ok.Ok.Ok.Ok.Ok.Ok.Ok" ]; then
              command=disable
              TRIPPOINT=$MAXTRIPPOINT
      else
              command=enable
              TRIPPOINT=$MINTRIPPOINT
     fi
      echo $command > $FAN
      # Temperature ramps up quickly, so pick this not too large:
      sleep 5

done