Fan control scripts

From ThinkWiki
Revision as of 11:48, 9 May 2005 by 217.231.111.61 (Talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

sh script example

#!/bin/sh

MAXTEMP=50

while [ 1 ];
do
       fan=no

       for temp in `sed s/temperatures:// < /proc/acpi/ibm/thermal`
       do
               test $temp -gt $MAXTEMP && fan=yes
       done

       command='disable'
       test "$fan" = "yes" && command='enable'
       echo $command > /proc/acpi/ibm/fan

       sleep 20
done

sh script example with more features

#!/bin/sh

# fan control-script
#
# based upon ibm-acpi 0.11 (experimental=1 !)
#
# eliminates anoying "fan always on" in battery mode
# works with hysteresis (DELTA) so that always-turn-on/turn-off is avoided
# fan acivates at MAXTEMP and cools down CPU, GPU etc. to MAXTEMP-DELTA than the fan is turned off
# furthermore detects if AC is on and gives back fan control to default behaviour than
#
# one can change MAXTEMP and DELTA to individual values
# but take care of your THINKPAD don`t melt it!
#
# have fun!
# mk 05.05.05

MAXTEMP=51
DELTA=4

SWITCHTEMP=$MAXTEMP

#make sure the script doesn't leave the fan off on error
trap "echo enable > /proc/acpi/ibm/fan" EXIT

while [ 1 ];
do
  for ac in `sed s/state:// < /proc/acpi/ac_adapter/AC/state`
    do
     if [ "$ac" = "off-line" ]; then
         fan=no
         for temp in `sed s/temperatures:// < /proc/acpi/ibm/thermal`
           do
             test $temp -gt $SWITCHTEMP && fan=yes
           done

         if [ "$fan" = "yes" ]; then
           command='enable'
           SWITCHTEMP=`expr $MAXTEMP - $DELTA`
         else
           SWITCHTEMP=$MAXTEMP
           command='disable'
         fi

       else # ac-adapter on -> set fan control to standard behaviour
         command='enable'
       fi

       echo $command > /proc/acpi/ibm/fan
       sleep 15
     done 
  done

init script example

#! /bin/sh

N=/etc/init.d/fan

set -e

case "$1" in
 start)
       # make sure privileges don't persist across reboots
       if [ -d /var/run/fan ] && [ "x`ls /var/run/fan`" != x ]
       then
               touch -t 198501010000 /var/run/fan/*
       fi
       fan.sh &    # Script from above
       ;;
 stop|reload|restart|force-reload)
       killall fan.sh
       echo enable > /proc/acpi/ibm/fan
       ;;
 *)
       echo "Usage: $N {start|stop|restart|force-reload}" >&2
       exit 1
       ;;
esac

exit 0