Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Manaual control over fans in PfSense (FreeBSD) on a Dell PowerEdge R210 ii system
# Original script:
# Install:
# sudo pkg install ipmitool
# Add ipmi_load="YES" to /boot/loader.conf
# Add this script to /usr/bin/
# Add * * * * * /bin/csh /usr/bin/ to cron file with sudo crontab -e
# Reboot
set temp_min=20
set temp_max=70
set fan_min=20
set fan_max=100
# Percentage of the old reading which will be used to calculate the new fan speed
set force=75
# Seconds between each reading
set delay=3
# Average only when difference is less than
set avg_skip=10
echo "Fan control started"
set fan_speed_old=58
if ( -f "/tmp/last_speed" ) then
set fan_speed_old=$(sed -n '1p' < "/tmp/last_speed")
echo "Last speed was $fan_speed_old"
# Enable manual control
ipmitool raw 0x30 0x30 0x01 0x00 > & /dev/null
while (1)
# Edit to work on BSD systems
set CURRENT_TEMP=`sysctl dev.cpu | grep temperature | awk '{print $2}'`
#Take the average temperature reading of all cores
foreach core_temp ($CURRENT_TEMP)
# Remove "C" from the end of the readings
set core_temp=`echo "$core_temp" | sed 's/.$//'`
set AVERAGE_TEMP=`echo "$AVERAGE_TEMP + $core_temp" | bc -l`
set NUMBER_OF_CORES=`echo "$NUMBER_OF_CORES + 1" | bc -l`
set temp=`echo "scale=0; $AVERAGE_TEMP / $NUMBER_OF_CORES" | bc -l`
# End edit
echo "CPU Temp: $temp"
@ fan_speed=($temp - $temp_min) * ($fan_max - $fan_min) / ($temp_max - $temp_min) + $fan_min
set res=`echo "$fan_speed-$fan_speed_old" | bc`
if ( $res < 0 ) then
set res=`expr 0 - $res`
if ( $res < $avg_skip ) then
echo " Averaging:"
set cforce=$(echo "scale=2;$force/100" | bc)
set old=$(echo "scale=2;$fan_speed_old*$cforce" | bc -l)
echo -e " Old speed $old"
set cforce=$(echo "scale=2;1-$cforce" | bc)
set new=$(echo "scale=2;$fan_speed*$cforce" | bc -l)
echo -e " New speed $new"
set fan_speed=$(echo "scale=0;$old+$new" | bc)
set fan_speed=$(echo "($fan_speed+0.5)/1" | bc )
echo -e " Fan speed: $fan_speed"
set fan_speed_old=$fan_speed
if ( $fan_speed < $fan_min ) then
set fan_speed=$fan_min
else if ( $fan_speed > $fan_max ) then
set fan_speed=$fan_max
set cmd="0x30 0x30 0x02 0xff 0x$fan_speed"
echo "Command: $cmd"
# Set fan speed
ipmitool raw $cmd > & /dev/null
set current=$(date +"%S")
set current=$(echo $current | sed 's/^0*//')
if ( $current > 51 ) then
echo $fan_speed_old > /tmp/last_speed
sleep 1
echo -e ""
sleep $delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment