-
-
Save kaysond/35f63c32a0a11daa9e0a53a9c200c1a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash | |
#You'll need to enable IPMI over lan in idrac first | |
#iDRAC Settings -> Network -> IPMI Settings | |
#Channel Privilege Level Limit needs to be Administrator | |
#You may want to create a dedicated username/pass with IPMI permission in iDRAC Settings -> User Authentication | |
IPMIHOST=idracip | |
IPMIUSER=username | |
IPMIPW=password | |
IPMIEK=0000000000000000000000000000000000000000 | |
FANSPEEDHEX="0x08" # See https://i.imgur.com/u1HMyqI.png | |
MAXTEMP=60 | |
HYSTERESIS=5 | |
FANFILE=/var/run/autofan | |
function ipmi() { | |
ipmitool -I lanplus -H "$IPMIHOST" -U "$IPMIUSER" -P "$IPMIPW" -y "$IPMIEK" "$@" | |
} | |
#For R710, which doesn't have cpu temps, try this line instead: | |
#if ! TEMPS=$(ipmi sdr type temperature | grep -i inlet | grep -Po '\d{2,3}' 2> /dev/null); | |
#thanks @bumbaclot | |
if ! TEMPS=$(ipmi sdr type temperature | grep -vi inlet | grep -vi exhaust | grep -Po '\d{2,3}' 2>&1); then | |
echo "FAILED TO READ TEMPERATURE SENSOR: $TEMP" >&2 | |
logger -t "fanctl" -p user.err -i "Error: Could not read temperature sensor" | |
fi | |
HIGHTEMP=0 | |
LOWTEMP=1 | |
for TEMP in $TEMPS; do | |
if [[ $TEMP > $MAXTEMP ]]; then | |
HIGHTEMP=1 | |
fi | |
if [[ $TEMP > $((MAXTEMP - HYSTERESIS)) ]]; then | |
LOWTEMP=0 | |
fi | |
done | |
if [[ -r "$FANFILE" ]]; then | |
AUTO=$(< "$FANFILE") | |
else | |
AUTO=1 | |
fi | |
if [[ $HIGHTEMP == 1 ]]; then | |
#Automatic fan control | |
ipmi raw 0x30 0x30 0x01 0x01 >& /dev/null || echo "FAILED TO SET FAN CONTROL MODE" >&2; exit 1 | |
echo "1" > "$FANFILE" | |
if [[ $AUTO == 0 ]]; then | |
logger -t "fanctl" -p user.info -i "Setting fan control to automatic" | |
fi | |
elif [[ $LOWTEMP == 1 ]]; then | |
#Manual fan control | |
ipmi raw 0x30 0x30 0x01 0x00 >& /dev/null || echo "FAILED TO SET FAN CONTROL SPEED" >&2; exit 1 | |
ipmi raw 0x30 0x30 0x02 0xff "$FANSPEEDHEX" >& /dev/null || echo "FAILED TO SET FAN SPEED" >&2; exit 1 | |
echo "0" > "$FANFILE" | |
if [[ $AUTO == 1 ]]; then | |
logger -t "fanctl" -p user.info -i "Setting fan control to manual" | |
fi | |
fi |
would it be something like c:>Bash script-filename.sh?
You'll need to configure iDRAC properly as indicated in the top comment, then change the first 4 variables in the script:
IPMIHOST=idracip
IPMIUSER=username
IPMIPW=password
IPMIEK=0000000000000000000000000000000000000000
Then you can run the script from any machine that can access the iDRAC IP. If you're running on Windows, you'll need to install WSL and a Linux distro first in order to use bash.
Assuming the script syntax is correct, and I'm not sure that it is because I'm not familiar with what looks like PowerShell, it would appear that the script is setting the fan speed based on the temperature ranges in the switch
statement.
yes it is Powershell ISE run as admin. It should invoke the $FanControl20 etc. It just does not seem to be doing it. Thanks though
Will try your .sh
Did; and:
C:\Users\Wesby_Designs\Documents\WindowsPowerShell\Scripts>bash fanctl.sh
FAILED TO READ TEMPERATURE SENSOR!
That suggests your IPMI configuration isn't working. Try setting the environment variables manually and running ipmi sdr type temperature
.
I also updated the script to show the error message when you run it.
Set Dedicated IPMI User; ran .sh and:
C:\Users\Wesby_Designs\Documents\WindowsPowerShell\Scripts>bash fanctl.sh
Error: Unable to establish IPMI v2 / RMCP+ session
FAILED TO READ TEMPERATURE SENSOR:
C:\Program Files\Dell\SysMgt\iDRACTools\IPMI>IPMITOOL -I wmi -H 1xxx -U xxx -P xxx sdr type temperature
Inlet Temp | 04h | ok | 7.1 | 26 degrees C
Exhaust Temp | 01h | ok | 7.1 | 32 degrees C
Temp | 0Eh | ok | 3.1 | 53 degrees C
Temp | 0Fh | ok | 3.2 | 51 degrees C
Do you have ipmitool installed in your bash environment? What happens if you run ipmitool -I lanplus -H "$IPMIHOST" -U "$IPMIUSER" -P "$IPMIPW" -y "$IPMIEK" sdr type temperature
in bash, replacing all the variables with their values as in your windows ipmitool command.
Yes Installed. Ran and:
C:\Users\Wesby_Designs\Documents\WindowsPowerShell\Scripts>bash fanctl.sh
Error: Unable to establish IPMI v2 / RMCP+ session
FAILED TO READ TEMPERATURE SENSOR:
FAILED TO SET FAN CONTROL SPEED
Seems pretty clear that its a connectivity or configuration issue and not an issue with the script itself, sorry. You'll have to figure out how to get ipmitool
working from your environment then the script should just work, assuming you've entered the host, user, etc correctly.
My only edit to have it work is:
function ipmi() {
ipmitool.exe -I lanplus -H "$IPMIHOST" -U "$IPMIUSER" -P "$IPMIPW" -y "$IPMIEK" $@
oh yeah it will work am sure both versions; am in agreement something in the servers idrac settings not right. When I first ran the PW script it did seem to work then I did bios idrac an lifecycle updates and then no go. So am now back to the older server profile but now can't get either PW script or your bash script to work....thank you very much for all your time and effort.
Resorting to repurposed server and start fresh.
THANKS KASOND great work on the script by the way!
Aram Hi thanks for the pointers. Hope all is well with you.
Connectivity set am able to log in to a dedicated IPMI serial channel VIA remote. Ran bash with no edits other than comments and variables. Response too a while getting a Server execution failed. :)
Hello,
I've developped a little Docker container based on someone else's to set manual fans speed and monitor CPUs temperatures. Don't hesitate to check, use & help : https://github.com/tigerblue77/Dell_iDRAC_fan_controller_Docker
Thanks !
Hi am interested in how to implement this on a Dell R720? Please let me know thanks.