Skip to content

Instantly share code, notes, and snippets.

@ConorShore
Created November 30, 2020 17:03
Show Gist options
  • Save ConorShore/a27c149c49622c7d42c6995d6e5b6cd1 to your computer and use it in GitHub Desktop.
Save ConorShore/a27c149c49622c7d42c6995d6e5b6cd1 to your computer and use it in GitHub Desktop.
A very simple fan controller to control D51B-2U fans via the IPMI interface
#!/bin/bash
#Conor Shore 2020
#Basic Fan Control Script For Quanta D51B-2U Server via IPMI
#designed to be used in init.d
### BEGIN INIT INFO
# Provides: IPMI Fan Controller
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Controls server fans
### END INIT INFO
#variable used for temp
cputemp=0
#the number the error will be multiplied by
factor=5
#target temp
target=40
#minimum fan level setting
minimum=11
#maximum fan level setting
maximum=100
#ip address of the IPMI interface
ipmiip="192.168.1.1"
# in brackets to run as background tax and not cause timeout
(while sleep 15
do
#get current temps of each cpu
cpu0=$(ipmitool -H $ipmiip -U admin -P admin sensor reading Temp_CPU0 | cut -f2 -d "|" | cut -f2 -d " ")
cpu1=$(ipmitool -H $ipmiip -U admin -P admin sensor reading Temp_CPU1 | cut -f2 -d "|" | cut -f2 -d " ")
#figure out which cpu is hotter
if [ $cpu0 -gt $cpu1 ]; then
cputemp=$cpu0
else
cputemp=$cpu1
fi
error=$((cputemp-target))
#new fan speed
newfan=$(((error*factor)+minimum))
#bounding fanspeed to max and min
if [ $newfan -lt $minimum ]; then
newfan=$minimum
fi
if [ $newfan -gt $maximum ]; then
newfan=$maximum
fi
#convert to hex
newfanhex=$(printf "%x" $newfan)
#issue commands
ipmitool -H $ipmiip -U admin -P admin raw 0x30 0x39 0x01 0x0 0x0 0x$newfanhex
ipmitool -H $ipmiip -U admin -P admin raw 0x30 0x39 0x01 0x0 0x1 0x$newfanhex
ipmitool -H $ipmiip -U admin -P admin raw 0x30 0x39 0x01 0x0 0x2 0x$newfanhex
ipmitool -H $ipmiip -U admin -P admin raw 0x30 0x39 0x01 0x0 0x3 0x$newfanhex
#write to syslog what happened this time around
logger "max cpu temp $cputemp setting fans to 0x$newfanhex"
done) &
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment