Guest User

Untitled

a guest
Jan 9th, 2020
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ----------------------------------------------------------------------------------
  4. # Script for checking the temperature reported by the ambient temperature sensor,
  5. # and if deemed too high send the raw IPMI command to enable dynamic fan control.
  6. #
  7. # This script was designed around the X11sat-f motherboard and having a nonPWM CPU fan
  8. #
  9. # Requires:
  10. # ipmitool: apt-get install ipmitool
  11. # slacktee.sh: https://github.com/course-hero/slacktee
  12.  
  13. #https://gist.github.com/kidpixo/04d61b42221f6bc8489b
  14. #https://forums.servethehome.com/index.php?resources/supermicro-x9-x10-x11-fan-speed-control.20/
  15. # ----------------------------------------------------------------------------------
  16.  
  17. ### VARIABLES FOR USER TO SET ###
  18.  
  19. # unRAID drives that are in the array/backplane of the fan we need to control
  20. HD[1]=/dev/sdb
  21. HD[2]=/dev/sdc
  22. HD[3]=/dev/sdd
  23. HD[4]=/dev/sde
  24. HD[5]=/dev/sdf
  25. HD[6]=/dev/sdg
  26. HD[7]=/dev/sdh
  27. HD[8]=/dev/sdi
  28. HD[9]=/dev/sdj
  29. HD[10]=/dev/sdk
  30. HD[11]=/dev/sdl
  31. HD[12]=/dev/sdm
  32. HD[13]=/dev/sdn
  33. HD[14]=/dev/sdo
  34. HD[15]=/dev/sdp
  35. HD[16]=/dev/sdq
  36. #HD[17]=/dev/sdr
  37. #HD[18]=/dev/sds
  38. #HD[19]=/dev/sdt
  39. #HD[20]=/dev/sdu
  40. #HD[21]=/dev/sdv
  41. #HD[22]=/dev/sdw
  42. #HD[23]=/dev/sdx
  43. #HD[24]=/dev/sdy
  44.  
  45. # Temperatures to change fan speed at
  46. # Any temp between OFF and HIGH will cause fan to run in a mapped value between idle and high speed
  47. TEMP_IDLE=28 # Anything between this number and below - fan is at idle speed
  48. TEMP_HIGH=40 # Anything above this number - fan is at alert speed
  49.  
  50. # Fan speed settings. For my board its a value between 0x00 and 0x64 (0% to 100%)
  51. FAN_OFF=0
  52. FAN_IDLE=8
  53. FAN_HIGH=20
  54. FAN_ALERT=50
  55.  
  56. ### END USER SET VARIABLES ###
  57. # Do not modify anything below
  58.  
  59. # Init Program variables
  60. NUM_OF_DRIVES=${#HD[@]}
  61. TEMP_HIGHEST=0
  62. CURRENT_DRIVE=1
  63. TEMP_CURRENT=0
  64.  
  65. # while loop to get the highest temperature of active drives.
  66. # If all are spun down then high temp will be set to 0.
  67. while [ "$CURRENT_DRIVE" -le "$NUM_OF_DRIVES" ]
  68. do
  69. #echo "Loop of: "${HD[$CURRENT_DRIVE]}
  70. SLEEPING=`hdparm -C ${HD[$CURRENT_DRIVE]} | grep -c standby`
  71. #echo $SLEEPING
  72.  
  73. if [[ $SLEEPING -eq 0 ]]
  74. then
  75. TEMP_CURRENT=`smartctl -A ${HD[$CURRENT_DRIVE]} | grep Temperature_Celsius | awk '{print $10}'`
  76. if [ $TEMP_HIGHEST -le $TEMP_CURRENT ]; then
  77. TEMP_HIGHEST=$TEMP_CURRENT
  78. fi
  79. fi
  80.  
  81. #echo $TEMP_CURRENT
  82. let "CURRENT_DRIVE+=1"
  83. done
  84.  
  85. echo "Highest temp is: "$TEMP_HIGHEST
  86.  
  87. # Set the PWM through IPMI
  88. INTERPOL_RANGE=$(($TEMP_HIGHEST-$TEMP_IDLE))
  89. if [ $TEMP_HIGHEST -gt $TEMP_HIGH ]
  90. then
  91. FAN_SPEED=$FAN_ALERT
  92.  
  93. elif [ $INTERPOL_RANGE -gt 0 ]
  94. then
  95. FAN_SPEED=$((((($TEMP_HIGHEST - $TEMP_IDLE) * ($FAN_HIGH - $FAN_IDLE)) / ($TEMP_HIGH - $TEMP_IDLE)) + $FAN_IDLE))
  96.  
  97. else
  98. FAN_SPEED=$FAN_IDLE
  99. fi
  100.  
  101. #echo "Setting fan speed to: "$FAN_SPEED
  102. if [ $FAN_SPEED -lt 10 ]
  103. then
  104. COMMANDSTR="ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x0"$FAN_SPEED
  105. else
  106. COMMANDSTR="ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x"$FAN_SPEED
  107. fi
  108.  
  109. echo "Running command: "$COMMANDSTR
  110. `$COMMANDSTR`
Advertisement
Add Comment
Please, Sign In to add comment