SHARE
TWEET

Untitled

a guest Nov 8th, 2019 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. CWD=$(dirname "$0")
  4.  
  5. # This file should contain: IDRAC_PASSWORD="YOUR_PASSWORD"
  6. . ${CWD}/fancontrol.env
  7.  
  8. IDRAC_HOST="idrac.yourdomain.com"
  9. IDRAC_USER="root"
  10. IPMI_CMD="ipmitool -I lanplus -H ${IDRAC_HOST} -U ${IDRAC_USER} -P ${IDRAC_PASSWORD}"
  11. TEMP_THRESHOLD="55"
  12. TMP_FILE="${CWD}/fancontrol.lock"
  13. TMP_FILE_THRESHOLD="7200"
  14. AVG_TEMP=$(${IPMI_CMD} sdr type temperature | awk '/0[E|F]h/ { total +=$9; count++ } END { print int(total/count) }' 2>/dev/null)
  15. AVG_TEMP=${AVG_TEMP:-0}
  16.  
  17. function log() {
  18.     echo "[$(date +'%Y-%m-%d %T')] $1"
  19. }
  20.  
  21. function rm_lock() {
  22.     rm -f ${TMP_FILE} # Remove the lock, we might lower the fans next invocation
  23. }
  24.  
  25. function set_fan_speed() {
  26.     # PERCENT:RPM 10:3300 20:4500 30:6500 40:8000 50:9500 60:10000 70:13000 80:15000 90:16000
  27.     log "Setting fan speed to ${1}%"
  28.     ${IPMI_CMD} raw 0x30 0x30 0x02 0xff $(printf '0x%x' ${1}) > /dev/null 2>&1
  29. }
  30.  
  31. log "Current temperature ${AVG_TEMP}C"
  32.  
  33. # Remove the lockfile if the system just booted or the lockfile is "old".
  34. # This prevents getting stuck in dynamic fan control mode after an reboot or iDRAC resets
  35. if [[ ( $(awk '{print int($1)}' /proc/uptime) -lt 600 ) || ( -f ${TMP_FILE} && $(($(date +%s) - $(date +%s -r ${TMP_FILE}))) -gt ${TMP_FILE_THRESHOLD} ) ]]; then
  36.     log "Removing stale lock file"
  37.     rm_lock
  38.  
  39.     # "3rd Party" PCIe cards like my LSI flashed H310 Mini make for loud fans
  40.     log "Disabling Third-Party PCIe Cooling Response"
  41.     ${IPMI_CMD} raw 0x30 0xce 0x00 0x16 0x05 0x00 0x00 0x00 0x05 0x00 0x01 0x00 0x00 > /dev/null 2>&1
  42. fi
  43.  
  44. if [[ $AVG_TEMP -gt $(($TEMP_THRESHOLD + 10)) ]]; then
  45.     rm_lock
  46.     log "Enabling dynamic fan control"
  47.     ${IPMI_CMD} raw 0x30 0x30 0x01 0x01 > /dev/null 2>&1
  48. elif [[ $AVG_TEMP -gt $TEMP_THRESHOLD ]]; then
  49.     rm_lock
  50.     set_fan_speed 40
  51. elif [[ ! -f "${TMP_FILE}" ]]; then
  52.     log "Disabling dynamic fan control"
  53.     ${IPMI_CMD} raw 0x30 0x30 0x01 0x00 > /dev/null 2>&1
  54.     set_fan_speed 25
  55.     touch ${TMP_FILE} # Create a temp file to prevent unecessary operations
  56. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top