Skip to content

Instantly share code, notes, and snippets.

@lampapetrol
Last active August 9, 2022 22:01
Show Gist options
  • Save lampapetrol/dbf1b22d0c0a8fc01b9376b8e357833f to your computer and use it in GitHub Desktop.
Save lampapetrol/dbf1b22d0c0a8fc01b9376b8e357833f to your computer and use it in GitHub Desktop.
My Dell Poweredge T330 was really loud but since I am to cheap to mod the cooling system i got this script to mitigate. The 1 minute polling frequency might be too short if you are doing cpu intensive stuff like video encoding. may variants available: https://www.google.com/search?q=dell_ipmi_fan_control.sh
#!/bin/bash
#
# To get rid of this script: https://www.pickysysadmin.ca/2021/01/25/silencing-my-dell-t340-part-3/
#
# chmod +x /scripts/dell_ipmi_fan_control.sh
# echo "*/1 * * * * root /bin/bash /usr/local/bin/dell_ipmi_fan_control.sh auto >> /var/log/cron.log" | sudo tee /etc/cron.d/dell_ipmi_fan_control
#
# https://stackoverflow.com/questions/60618155/unable-to-connect-to-ipmi-interface-from-same-server-where-ipmi-is
IDRACIP=""
IDRACUSER=""
IDRACPASSWORD=""
if [[ -n $IDRACIP ]]
then
# remote access
IPMI_OPTS="-I lanplus -H $IDRACIP -U $IDRACUSER -P $IDRACPASSWORD"
else
# local access through IPMB
IPMI_OPTS="-m 0x20"
fi
# https://www.reddit.com/r/homelab/comments/t9pa13/dell_poweredge_fan_control_with_ipmitool/
SENSORNAME="^Temp"
# speed in base 16: 0x00 (100%) to 0x64 (100%)
SPEED_BASE16_LOW="0x0f" # 0x0f is 15%
SPEED_BASE16_MID="0x14" # 0x14 is 20%
TEMPTHRESHOLD_1="39"
TEMPTHRESHOLD_2="44"
echoerr() {
echo "$@" 1>&2
}
function log_prefix() {
date +%Y-%m-%d'T'%H:%M:%S
}
function get_temp() {
ipmitool $IPMI_OPTS sdr type temperature | grep -e $SENSORNAME | cut -d "|" -f5 | cut -d " " -f2 | grep -v "Disabled"
}
function dynamic_fan_control() {
echo "$(log_prefix) - disable manual fan control"
ipmitool $IPMI_OPTS raw 0x30 0x30 0x01 0x01
}
function static_fan_control() {
local hexspeed=$1
# echo "$(log_prefix) - enable manual fan control"
ipmitool $IPMI_OPTS raw 0x30 0x30 0x01 0x00
echo "$(log_prefix) - set fan speed to $(($hexspeed))%"
ipmitool $IPMI_OPTS raw 0x30 0x30 0x02 0xff $hexspeed
}
function auto_fan_control() {
current_temp=$(get_temp)
echo "$(log_prefix) - current temperature: $current_temp"
if [[ $current_temp > $TEMPTHRESHOLD_2 ]]
then
dynamic_fan_control
elif [[ $current_temp > $TEMPTHRESHOLD_1 ]]
then
static_fan_control $SPEED_BASE16_MID
else
static_fan_control $SPEED_BASE16_LOW
fi
}
case "$1" in
auto)
auto_fan_control
;;
dynamic)
dynamic_fan_control
;;
static)
# default to midspeed
speed=${2-$SPEED_BASE16_MID}
static_fan_control "$speed"
;;
*)
echoerr "$1 is not a supported profile: auto|static|dynamic"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment