Skip to content

Instantly share code, notes, and snippets.

@mendelgusmao
Created May 5, 2016 19:48

Revisions

  1. mendelgusmao created this gist May 5, 2016.
    27 changes: 27 additions & 0 deletions fan.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    minSpeed=1500
    maxSpeed=5500
    highTemp=70
    normalTemp=40

    output=/sys/devices/platform/applesmc.768/fan1_output
    manual=/sys/devices/platform/applesmc.768/fan1_manual

    currentSpeed=$(cat $output)

    [ "$1" = "" ] && echo $currentSpeed && exit 0

    if [ "$1" = "auto" ]; then
    currentTemp=$(sensors | awk -F'[^0-9]*' '/Core/{sum = sum + $3; total = total + 1}END{OFMT = "%.0f"; print sum / total}')
    newSpeed=$(echo "$minSpeed + (($maxSpeed - $minSpeed) / ($highTemp - $normalTemp) * ($currentTemp - $normalTemp))" | bc | cut -d. -$
    if [ $newSpeed -eq $currentSpeed ]; then
    exit 0
    fi
    else
    newSpeed=$1
    fi
    bash -c "echo 1 > $manual"
    bash -c "echo $newSpeed > $output"
    #sudo bash -c "echo 0 > $manual"
    echo "$currentSpeed > $(cat $output) @ $currentTemp"