-
-
Save alvesvaren/85c8dd14077dee98925631425cad606f to your computer and use it in GitHub Desktop.
Dell R710 (and possibly other) temperature-based fan speeds script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script for checking the temperature reported by the ambient temperature sensor, | |
# and if deemed too high send the raw IPMI command to enable dynamic fan control. | |
# | |
# Also get CPU temps from lm-sensors and adjust fan speeds according to defined | |
# speed % which should be set according to your needs (each CPU model will vary) | |
# | |
# Requires: | |
# ipmitool – apt install ipmitool | |
# sensors - apt install lm-sensors | |
# bc - apt install bc | |
LASTSPEED=$(cat /tmp/lastspeed 2>/dev/null || echo 0) | |
function setfans () { | |
speed=$1 | |
if [[ $speed == "auto" ]]; then | |
# Enable automatic fan speed control | |
ipmitool raw 0x30 0x30 0x01 0x01 >/dev/null 2>&1 & | |
LASTSPEED=${speed} | |
echo "[$(date)] $(hostname) FANS: AUTO (SYS: ${SYSTEMP}C, CPU: ${CPUTEMP}C)" | |
echo "AUTO (SYS: ${SYSTEMP}C, CPU: ${CPUTEMP}C)" | systemd-cat -t updatefans | |
else | |
speedhex=$(echo "obase=16; $speed" | bc) | |
# Enable manual fan speed control | |
if [[ "$LASTSPEED" == "auto" ]] || [[ "$LASTSPEED" == "0" ]]; then | |
ipmitool raw 0x30 0x30 0x01 0x00 >/dev/null 2>&1 # & | |
fi | |
ipmitool raw 0x30 0x30 0x02 0xff 0x${speedhex} >/dev/null 2>&1 & | |
LASTSPEED=${speed} | |
echo "[$(date)] $(hostname) FANS: ${speed}% (0x${speedhex}) (SYS: ${SYSTEMP}C, CPU: ${CPUTEMP}C)" | |
echo "${speed}% (0x${speedhex}) (SYS: ${SYSTEMP}C, CPU: ${CPUTEMP}C)" | systemd-cat -t updatefans | |
fi | |
} | |
# This variable sends a IPMI command to get the temperature, and outputs it as two digits. | |
SYSTEMP=$(ipmitool sdr type temperature | grep Ambient | grep degrees | grep -Po '\d{2}' | tail -1) | |
#highest of all core temps | |
CPUTEMP=$(sensors | grep high | cut -d "+" -f2 | cut -d "." -f1 | sort -n | tail -1) | |
# Use the cpu temperature to calculate an optimal fan speed compared to the temperature using the formula x^2/50 | |
let "SPEED=$CPUTEMP**2/50" | |
# Ceil the value | |
SPEED=$(echo $SPEED | awk '{print int($1+0.5)}') | |
if [[ $SYSTEMP > 32 || $CPUTEMP > 65 ]]; then | |
echo "Warning: SysTemp or CpuTemp too high! Activating dynamic fan control! ($SYSTEMP C)" | |
echo "Warning: SysTemp or CpuTemp too high! Activating dynamic fan control! ($SYSTEMP C)" | systemd-cat -p "warning" -t updatefans | |
setfans auto | |
else | |
setfans $SPEED | |
fi | |
echo $LASTSPEED > /tmp/lastspeed |
FYI, I had to run sudo chmod -t /tmp
in order to get $LASTSPEED
to save
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, i like your optimal fan speed calc