Advertisement
Guest User

autofan.sh

a guest
Jun 19th, 2011
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##########################################################################
  4. #
  5. # Script to control (AMD/ATI) fanspeeds depending on the GPUs temperature
  6. #
  7. # Copyright 2011 Markus Niemann (markus@chanoa.de)
  8. #
  9. ##########################################################################
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22. ##########################################################################
  23. #
  24. # Usage: [screen -dmS fan#] autofan.sh {DeviceID}
  25. #
  26. ##########################################################################
  27. DEVICE=$1
  28. export DISPLAY=:0.${DEVICE}
  29.  
  30. # initial fanspeed
  31. FANSPEED=75
  32.  
  33. # maximum temperature, toggles 100% fanspeed
  34. MAXTEMP=80
  35.  
  36. # middle temperature, exceeding this temperature will speed up fan
  37. MIDTEMP=78
  38.  
  39. # minimum temperature, deceeding this temperature will speed down fan
  40. MINTEMP=76
  41.  
  42. # minimum fanspeed
  43. MINSPEED=60
  44.  
  45. # percentage fanspeed steps this script will toggle
  46. FANSTEPS=2
  47.  
  48. # time interval in seconds this script will check temperature
  49. SLEEP=20
  50.  
  51. if [ $# -ne 1 ]
  52. then
  53.   echo "Usage: `basename $0` {DeviceID}"
  54.   exit $E_BADARGS
  55. fi
  56.  
  57. function getTemp {
  58.     currenttemp=$(sudo aticonfig --odgt --adapter=$DEVICE | grep C)
  59.     currenttemp=${currenttemp##*- }
  60.     echo ${currenttemp%%.*}
  61. }
  62.  
  63. function setFanSpeed {
  64.     case $1 in
  65.         up)
  66.             if [ $FANSPEED -lt 100 ]
  67.             then
  68.                 FANSPEED=$((FANSPEED+FANSTEPS))
  69.                 echo up to $FANSPEED %
  70.                 sudo aticonfig --pplib-cmd "set fanspeed 0 $FANSPEED" > /dev/null
  71.             else
  72.                 echo Fanspeed already 100%!
  73.             fi
  74.         ;;
  75.         down)
  76.             if [ $FANSPEED -gt $MINSPEED ]
  77.             then
  78.                 FANSPEED=$((FANSPEED-FANSTEPS))
  79.                 echo down to $FANSPEED %
  80.                 sudo aticonfig --pplib-cmd "set fanspeed 0 $FANSPEED" > /dev/null
  81.             else
  82.                 echo Fanspeed already low enough!
  83.             fi
  84.         ;;
  85.         *)
  86.             FANSPEED=$1
  87.             echo up to $FANSPEED %
  88.             sudo aticonfig --pplib-cmd "set fanspeed 0 $FANSPEED" > /dev/null
  89.         ;;
  90.     esac
  91. }
  92.  
  93. setFanSpeed $FANSPEED
  94.  
  95. while [ 0 == 0 ]
  96. do
  97.     sleep $SLEEP
  98.     TEMP=`getTemp`
  99.     echo Temp is $TEMP
  100.     if [[ $TEMP -ge $MAXTEMP ]]
  101.     then
  102.         setFanSpeed 100
  103.     else
  104.         if [[ $TEMP -ge $MIDTEMP ]]
  105.         then
  106.             setFanSpeed up
  107.         else
  108.             if [[ $TEMP -le $MINTEMP ]]
  109.             then
  110.                 setFanSpeed down
  111.             fi
  112.         fi
  113.     fi
  114. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement