jms1989

fan speed for dell t320

Oct 17th, 2021
995
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. set -x #for debugging
  3. #Stops script on errors, unset variables or failing pipeline
  4. set -euo pipefail
  5.  
  6. # ensure manual controls are available
  7. ipmitool -I open raw 0x30 0x30 0x01 0x00
  8.  
  9. #variables definitions
  10. LOG=/var/log/ipmi.log
  11.  
  12. #functions
  13. ##Set Fan Speed, accept one argument to set speed
  14. FanSpeed()
  15. {
  16.         ipmitool -I open raw 0x30 0x30 0x02 $1
  17. }
  18.  
  19.  
  20. ##Get Temp values
  21. GetValues()
  22. {
  23.         #Get motherboard, cpu1 and cpu2 temperature
  24.         OUTPUT=$(/usr/bin/ipmitool -I open sdr type temperature |egrep '0Eh|04h' | awk -F'|' '{ print $5 $9 $13 }' | awk '{ print $1 }'|tr '\n' "+" |sed s/+$//g)
  25.         #motherboard+cpu1+cpu2 temp
  26.         LOG_TOTAL=$(($OUTPUT))
  27.         #Get Fan1 speed
  28.         FANS=$(ipmitool -I open sensor reading "Sys Fan1" | awk '{ print $3 }')
  29. }
  30.  
  31. GetValues
  32. echo "$(date "+%Y-%m-%d %H:%M:%S")" "LOG_TOTAL : $LOG_TOTAL"
  33.  
  34. while :
  35. do
  36.         if [ "$LOG_TOTAL" -le 60 ] && [ $FANS -le 2520 ]; then
  37.                 echo "$(date "+%Y-%m-%d %H:%M:%S")" "FAN speed : 2520, <= 2520 don't do anything" | tee -a "$LOG"
  38.         elif [ "$LOG_TOTAL" -le 60 ] && [ $FANS -ne 2520 ]; then
  39.                 FanSpeed "0xff 0x05" #Set speed to 2520
  40.                 echo "$(date "+%Y-%m-%d %H:%M:%S")" "Set speed to 2520" | tee -a "$LOG"
  41.         elif [ "$LOG_TOTAL" -gt 60 ] && [ "$LOG_TOTAL" -le 65 ] && [ $FANS -ne 2880 ]; then
  42.                 FanSpeed "0xff 0x07" #Set speed to 2880
  43.                 echo "$(date "+%Y-%m-%d %H:%M:%S")" "Set speed to 2880" | tee -a "$LOG"
  44.         elif [ "$LOG_TOTAL" -gt 65 ] && [ "$LOG_TOTAL" -le 75 ] && [ $FANS -ne 2040 ]; then
  45.                 FanSpeed "0xff 0x0A" #Set speed to 3240
  46.                 echo "$(date "+%Y-%m-%d %H:%M:%S")" "Set speed to 3240" | tee -a "$LOG"
  47.         elif [ "$LOG_TOTAL" -gt 75 ] && [ "$LOG_TOTAL" -le 85 ] && [ $FANS -ne 7320 ]; then
  48.                 FanSpeed "0xff 0x23" #Set speed to 7320
  49.                 echo "$(date "+%Y-%m-%d %H:%M:%S")" "Set speed to 7320" | tee -a "$LOG"
  50.         elif [ "$LOG_TOTAL" -gt 90 ] && [ $FANS -ne 10200 ]; then
  51.                 FanSpeed "0xff 0x32" #Set speed to 10200
  52.                 echo "$(date "+%Y-%m-%d %H:%M:%S")" "Set speed to 10200" | tee -a "$LOG"
  53.         fi
  54.         sleep 30s
  55.         GetValues
  56.         echo "$(date "+%Y-%m-%d %H:%M:%S")" "$LOG_TOTAL" >> "$LOG"
  57.         echo "$(date "+%Y-%m-%d %H:%M:%S")" "FAN speed : $FANS" | tee -a "$LOG"
  58. done
  59.  
RAW Paste Data