Hi,
I wrote a script to control my fan.
The fan speed is controlled by the temp of the CPU.
I'm pretty new to bash so I'm hoping for some feedback and off course is everybody free to use the script how they like.
Thx in advance
	
	
	
	
	
I wrote a script to control my fan.
The fan speed is controlled by the temp of the CPU.
I'm pretty new to bash so I'm hoping for some feedback and off course is everybody free to use the script how they like.

Code:
#!/bin/bash
#MikeD
#Automatic fan on cpu temp
CHECK_TIME=10 #IN SEC
function pwm(){
LOOP=0
while [ $LOOP -lt $(($CHECK_TIME*75)) ]; do
        echo 1 > /sys/class/gpio/gpio82/value
        sleep $1
        echo 0 > /sys/class/gpio/gpio82/value
        sleep $2
        LOOP=$(($LOOP+1))
done
}
function fanOff()
{
echo 0 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}
function fanTweFiv()
{
pwm .0025 .0075
}
function fanFifty()
{
pwm .0050 .0050
}
function fanSevFiv()
{
pwm .0075 .0025
}
function fanFull()
{
echo 1 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}
while [ 1 ]; do
        TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
        if [ $TEMP -le 20000 ]
        then
                fanOff
        fi
        if [ $TEMP -gt 20000  -a  $TEMP -le 35000 ]
        then
                fanTweFiv
        fi
        if [ $TEMP -gt 35000 -a $TEMP -le 50000 ]
        then
                fanFifty
        fi
        if [ $TEMP -gt 50000 -a $TEMP -le 65000 ]
        then
                fanSevFiv
        fi
        if [ $TEMP -gt 65000 ]
        then
                fanFull
        fi
doneThx in advance
	
