Skip to content

Instantly share code, notes, and snippets.

@lixin9311
Created June 3, 2021 10:35
Show Gist options
  • Save lixin9311/c40a62d7acdba009e03b7ef177c8cf43 to your computer and use it in GitHub Desktop.
Save lixin9311/c40a62d7acdba009e03b7ef177c8cf43 to your computer and use it in GitHub Desktop.
idrac fan control
#!/bin/bash
## T620 Fan Script Inspired by https://github.com/NoLooseEnds/Scripts/tree/master/R710-IPMI-TEMP
## Require user (non-sudo) access to ipmitool (essentially /dev/ipmi0)
## Possible solution: chown :sudo `which ipmitool`; chmod u+s `which ipmitool`
## To disable dynamic fan control: ipmitool -I lanplus -H $IDRACIP -U $IDRACUSER -P $IDRACPASSWORD raw 0x30 0x30 0x01 0x00
IDRACIP="192.168.1.xxx"
IDRACUSER="root"
IDRACPASSWORD="your_awesome_password"
get_speed() {
awk 'BEGIN{cur = ARGV[1]; ARGC = 1}
$1 > cur{
printf "%d", int(rpm + ($2 - rpm) / ($1 - temp) * (cur - temp))
exit
}
{temp = $1; rpm = $2}
' $1 << EOF
40 10
45 20
50 40
60 60
80 80
90 100
10000 100
EOF
}
adjust_speed() {
ipmitool -I lanplus -H $IDRACIP -U $IDRACUSER -P $IDRACPASSWORD raw 0x30 0x30 0x02 0xff $(printf "0x%02x" $1) &>/dev/null
}
# Enable manual fan speed
ipmitool -I lanplus -H $IDRACIP -U $IDRACUSER -P $IDRACPASSWORD raw 0x30 0x30 0x01 0x00 &>/dev/null
speed=0
while true; do
sleep 5
maxtmp=$(ipmitool -I lanplus -H $IDRACIP -U $IDRACUSER -P $IDRACPASSWORD sdr type temperature 2>&1 | cut -d'|' -f5 | awk '{if(m<$1) m=$1} END{if(m){print m}else{print "ERROR"}}')
if [ $maxtmp == "ERROR" ]; then
#echo "[$(date "+%F %T")] Warning: ipmi read error!!!" >&2
logger -t fan.sh --id=$$ "Warning: IPMI read error! Try spin fan to 100%!"
adjust_speed 75
else
new_speed=$(get_speed $maxtmp)
echo $(date +'%Y/%m/%d %H:%M:%S') : $maxtmp C, set fan speed to $new_speed
if [ "$new_speed" -eq "$speed" ]; then
continue
fi
speed=$new_speed
#echo "[$(date "+%F %T")] Temp=$maxtmp Speed=$speed%"
logger -t fan.sh --id=$$ "Temp=$maxtmp Speed=$speed%"
adjust_speed $speed
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment