Skip to content

Instantly share code, notes, and snippets.

@rshk
Created January 8, 2013 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rshk/4482729 to your computer and use it in GitHub Desktop.
Save rshk/4482729 to your computer and use it in GitHub Desktop.
#!/bin/bash
##----------------------------------------------------------------------
## Keep the temperature down, for Thinkpads
##
## Useful for people that prefer the computer noisy than
## red hot.
## When a MAX temperature is reached, the fan speed is raised
## to its maximum power until the temperature drops below
## another MIN thresold.
##
## WARNING! This script was not tested against fan durability.
## IBM quality should be enough warranty, but we never know.
## You warned!
##
## Copyright (C) 2012 - Samuele Santi <redshadow@hackzine.org>
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##----------------------------------------------------------------------
##============================================================
## Settings
##============================================================
TEMP_MIN=55
TEMP_MAX=62
SLEEP_TIME=2s
##============================================================
PREV_TEMP=9999
COOLING_DOWN=0
PREVMSG=""
function log_msg() {
if [ "$1" == "$PREVMSG" ]; then return; fi
echo "[$( date +'%F %T' )]" "$1"
PREVMSG="$1"
}
function set_fan_level() {
echo level "$1" > /proc/acpi/ibm/fan
}
while :; do
CURRENT_TEMP="$( cat /proc/acpi/ibm/thermal | cut -f2 | cut -d' ' -f1 )"
if [ "$CURRENT_TEMP" -gt "$TEMP_MIN" ]; then
if [ "$CURRENT_TEMP" -ge "$TEMP_MAX" ]; then
## We absolutely need some cooling!
log_msg "Temperature is ${CURRENT_TEMP} -> over the ${TEMP_MAX} limit."
set_fan_level full-speed
COOLING_DOWN=1
elif [ "$COOLING_DOWN" == "1" ]; then
## Continue cooling down until TEMP_MIN reached
log_msg "Temperature is ${CURRENT_TEMP} -> cooling down to ${TEMP_MIN}."
set_fan_level full-speed
else
## Keep cool, but with normal fan speed
log_msg "Temperature is ${CURRENT_TEMP}, over the MIN limit of ${TEMP_MIN}, but MAX limit of ${TEMP_MAX} not reached yet."
set_fan_level 7
fi
else
## Use auto level
log_msg "Temperature is ${CURRENT_TEMP}, below MIN limit of ${TEMP_MIN}."
set_fan_level auto
COOLING_DOWN=0
fi
PREV_TEMP=$CURRENT_TEMP
sleep "$SLEEP_TIME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment