January 24Jan 24 I've got an Asus Pro WS W880-ACE SE motherboard in a Jonsbo N5 case with Noctua chassis fans and an LSI 9305-16i HBA. It is a cool case, but hard drive cooling is not exactly one of its strong suits. I'm considering a 3D-printed hard drive fan addon, but first, I'd really very much like my chassis fans to just spin faster when the drives heat up.Seems like FanCtrl Plus only works with a PWM controller, and I can't find any place in the BIOS to set the W880's fan control to PWM. I guess it's IPMI only.And I can't find any settings in IPMI Tools to turn the fans faster when the drives heat up.A user in the W680 thread got ChatGPT to write a script to do this. But this seems like such a basic function, just curious if anyone has any other ideas? Something I'm overlooking?
February 16Feb 16 I'm the guy with the script from the other thread. I searched and tested extensively... nothing worked if you want to use HDD temperatures as a trigger. I also tried modifying the IPMItools plugin... to no avail. The only thing is, my IPMI card from the mainboard has three temperature sensors. You could put one on an HDD and control it based on that. But that's inaccurate if you have many HDDs.I'd be happy to give you my current script, which has been refined over several months. Analyze it with AI and test it if you like. I'm very happy with it now, and after all this time, I have a lot of confidence in it.Fan_Control (at startup of array):Fan_Control#!/bin/bash# Fan_Control# Only for ASUS Pro WS W680-ACE IPMI PCIe-CARD# V1.9 - Thermal-focused disks.ini Parsing - 27.01.2026# Umbau auf device-basiertes Parsing ohne Status-Filter.# Inkl. Sicherheitswerten (secure_pwm) und Peak-Hold für alle Sensoren.# Fix: SecureMode greift nur noch bei echtem Array-Stop (mdState Check). # =======================# ⚙️ Globale Einstellungen# ======================= INTERVAL=5 # Intervall in Sekunden für SchleifendurchlaufDRY_RUN=0 # 1 = Testmodus (kein IPMI-Befehl), 0 = aktivFAILSAFE_FAN_SPEED=60 # Notfallgeschwindigkeit bei IPMI-Fehler AFTER_ACTIVITY_COOLDOWN_HDD=900 # Zeit (Sekunden), Unraid legt HDDs schlafen - Zeit für Lüfter auf letzten Wert bevor BaseAFTER_PEAK_TEMP_COOLDOWN_HDD=300 # Zeit (Sekunden), Peak-Hold HDDAFTER_PEAK_TEMP_COOLDOWN_NVME=180 # Zeit (Sekunden), Peak-Hold NVMe # Individuelle Peak-Cooldowns für TR-SensorenAFTER_PEAK_TEMP_COOLDOWN_TR1=180 # RAM CooldownAFTER_PEAK_TEMP_COOLDOWN_TR2=180 # HBA CooldownAFTER_PEAK_TEMP_COOLDOWN_TR3=180 # GPU Cooldown MAX_SAFE_HDD_TEMP=53 # Temperaturgrenze HDDs → Failsafe 100%MAX_SAFE_NVME_TEMP=80 # Temperaturgrenze NVMe → Failsafe 100%MAX_SAFE_CPU_TEMP=95 # Temperaturgrenze CPU → Failsafe 100% # Individuelle Max-Safe-Temperaturen für TR-SensorenMAX_SAFE_TR1_TEMP=65 # RAM MaxMAX_SAFE_TR2_TEMP=75 # HBA MaxMAX_SAFE_TR3_TEMP=85 # GPU Max LOGFILE="/tmp/user.scripts/tmpScripts/Fan_Control/log.txt" # ====================================# ⚙️ Sicherheits-Lüfterwerte (NUR wenn Array wirklich GESTOPPT ist)# ====================================declare -A secure_pwmsecure_pwm["CHA_FAN1"]=59 # unten links HDDssecure_pwm["CHA_FAN2"]=59 # unten mitte HDDssecure_pwm["CHA_FAN3"]=59 # unten rechts HDDssecure_pwm["CHA_FAN4"]=60 # oben links MB & links hinten HBAsecure_pwm["CHA_FAN5"]=30 # oben mittesecure_pwm["CHA_FAN6"]=30 # oben rechts Richtung CPUsecure_pwm["CHA_FAN7"]=62 # hinten Gehäuseentlüftungsecure_pwm["CHA_FAN8"]=42 # CPU Kühler # ====================================# 🔍 Preflight: benötigte Tools prüfen# ==================================== missing_tools=()for cmd in sensors ipmi-raw ipmi-sensors awk; do if ! command -v "$cmd" >/dev/null 2>&1; then missing_tools+=("$cmd") fidone if (( ${#missing_tools[@]} > 0 )); then timestamp=$(date '+%F | %T') echo "❌ [$timestamp] Missing required tools: ${missing_tools[*]}" >> "$LOGFILE" exit 1fi # ====================================# 🧭 Steuerlogik je CHA_FANx (1–8)# ====================================declare -A fan_sourcesfan_sources["CHA_FAN1"]="HDD" # unten links HDDsfan_sources["CHA_FAN2"]="HDD" # unten mitte HDDsfan_sources["CHA_FAN3"]="HDD" # unten rechts HDDsfan_sources["CHA_FAN4"]="HDD CPU NVME TR2 TR3" # oben links MB & links hinten HBAfan_sources["CHA_FAN5"]="CPU NVME TR3" # oben mittefan_sources["CHA_FAN6"]="CPU TR1 TR3" # oben rechts Richtung CPUfan_sources["CHA_FAN7"]="HDD CPU NVME TR1 TR3" # hinten Gehäuseentlüftungfan_sources["CHA_FAN8"]="CPU" # CPU Kühler # ====================================# 💾 Device-Zuordnungen# ====================================declare -A fan_disksfan_disks["CHA_FAN1"]="sde sdf sdg sdh sdc sdd"fan_disks["CHA_FAN2"]="sde sdf sdg sdh sdc sdd"fan_disks["CHA_FAN3"]="sde sdf sdg sdh sdc sdd"fan_disks["CHA_FAN4"]="sde sdf sdg sdh sdc sdd"fan_disks["CHA_FAN7"]="sde sdf sdg sdh sdc sdd" declare -A fan_nvmesfan_nvmes["CHA_FAN4"]="nvme0n1 nvme1n1 nvme2n1"fan_nvmes["CHA_FAN5"]="nvme0n1 nvme1n1 nvme2n1"fan_nvmes["CHA_FAN7"]="nvme0n1 nvme1n1 nvme2n1" # ====================================# 📈 Kurven-Definitionen# ====================================declare -A hdd_curve_maphdd_curve_map["CHA_FAN1"]="1=25 40=59 45=70 50=90 55=100"hdd_curve_map["CHA_FAN2"]="1=25 40=59 45=70 50=90 55=100"hdd_curve_map["CHA_FAN3"]="1=25 40=59 45=70 50=90 55=100"hdd_curve_map["CHA_FAN4"]="1=30 30=50 40=60 45=72 55=85"hdd_curve_map["CHA_FAN5"]="1=30 40=50 45=70 50=90 55=100"hdd_curve_map["CHA_FAN6"]="1=30 40=50 45=70 50=90 55=100"hdd_curve_map["CHA_FAN7"]="1=30 30=52 40=62 45=72 55=100"hdd_curve_map["CHA_FAN8"]="1=42 40=50 45=70 50=90 55=100" declare -A nvme_curve_mapnvme_curve_map["CHA_FAN4"]="1=30 45=50 50=60 70=90 80=100"nvme_curve_map["CHA_FAN5"]="1=30 45=50 50=60 70=90 80=100"nvme_curve_map["CHA_FAN7"]="1=30 45=62 60=72 70=90 80=100" declare -A cpu_curve_mapcpu_curve_map["CHA_FAN1"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN2"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN3"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN4"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN5"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN6"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN7"]="1=30 75=62 80=70 90=90 95=100"cpu_curve_map["CHA_FAN8"]="1=42 75=50 80=80 90=90 95=100" declare -A tr1_curve_map # RAMtr1_curve_map["CHA_FAN6"]="1=30 45=49 55=60 60=80 65=100"tr1_curve_map["CHA_FAN7"]="1=30 45=62 55=72 60=90 65=100" declare -A tr2_curve_map # HBAtr2_curve_map["CHA_FAN4"]="1=30 50=50 60=75 65=90 70=100" declare -A tr3_curve_map # GPUtr3_curve_map["CHA_FAN4"]="1=30 50=50 60=65 70=85 80=100"tr3_curve_map["CHA_FAN5"]="1=30 50=50 60=65 70=85 80=100"tr3_curve_map["CHA_FAN6"]="1=30 50=50 60=65 70=85 80=100"tr3_curve_map["CHA_FAN7"]="1=30 50=62 60=65 70=85 80=100" # ====================================# 🧠 Zustands-Tracking & Helfer# ====================================declare -A last_pwm cached_hdd_temp cached_hdd_time nvme_temp_current nvme_time_currentdeclare -A hdd_peak_pwm hdd_peak_time nvme_peak_pwm nvme_peak_time ipmi_tempsdeclare -A tr_peak_pwm tr_peak_time warned_missing_curve log_echo() { echo "$1" >> "$LOGFILE" [[ $(wc -l < "$LOGFILE" 2>/dev/null) -gt 150 ]] && tail -n 100 "$LOGFILE" > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"} step_curve_pwm() { local temp=$1 curve_string=$2 last_p=0 [[ -z "$curve_string" ]] && echo 0 && return for pair in $curve_string; do local t="${pair%=*}" pwm="${pair#*=}" (( temp < t )) && echo "$last_p" && return last_p=$pwm done echo "$last_p"} get_first_pwm_from_curve() { for pair in $1; do echo "${pair#*=}"; return; done echo 10} # ====================# 🔁 Hauptschleife# ====================while true; do now=$(date +%s) # --- Array Status Check --- array_state=$(grep "mdState=" /var/local/emhttp/var.ini | cut -d'"' -f2) # 1. CPU Temp cpu_temp=$(sensors 2>/dev/null | awk '/Package id 0:/ {print int($4)}' | head -n1) # 2. IPMI-Sensoren Snapshot while read -r line; do name=$(echo "$line" | cut -d'|' -f2 | xargs) val=$(echo "$line" | cut -d'|' -f5 | xargs) case "$name" in "TR1 Temperature") ipmi_temps["TR1"]=$val ;; "TR2 Temperature") ipmi_temps["TR2"]=$val ;; "TR3 Temperature") ipmi_temps["TR3"]=$val ;; esac done < <(ipmi-sensors --quiet-cache --output-sensor-state --sensor-types Temperature) # 3. HDD & NVMe Scan via disks.ini (Robustes State-Machine Parsing) while IFS='|' read -r dev temp spun status; do if [[ -n "$dev" ]]; then if [[ "$dev" == sd* ]]; then if [[ "$spun" == "0" && "$temp" =~ ^[0-9]+$ ]]; then cached_hdd_temp[$dev]=$temp cached_hdd_time[$dev]=$now fi elif [[ "$dev" == nvme* ]]; then if [[ "$temp" =~ ^[0-9]+$ ]]; then nvme_temp_current[$dev]=$temp nvme_time_current[$dev]=$now fi fi fi done < <(awk -F'=' ' function flush() { if (dev != "") { print dev "|" temp "|" spun "|" stat } } { gsub(/["\[\],]/, "", $0) if ($1 == "device") { flush() dev = $2 temp=""; spun=""; stat="" } else if ($1 == "temp") { temp = $2 } else if ($1 == "spundown") { spun = $2 } else if ($1 == "status") { stat = $2 } } END { flush() } ' /var/local/emhttp/disks.ini) # 5. Fan-Loop for i in {1..8}; do fan="CHA_FAN$i"; sources="${fan_sources[$fan]}" [[ -z "$sources" ]] && continue final_speed=0 final_driver="" data_found=0 hdd_display="(not used)"; nvme_display="(not used)"; tr_display="" zone_hex=$(printf '0x%02x' $((i - 1))) for src in $sources; do case $src in HDD) curve_str="${hdd_curve_map[$fan]}" [[ -z "$curve_str" ]] && continue cur_h_p=0; max_h=-1; max_h_dev="" for d in ${fan_disks[$fan]}; do if [[ -n "${cached_hdd_time[$d]}" && $(( now - cached_hdd_time[$d] )) -lt $AFTER_ACTIVITY_COOLDOWN_HDD ]]; then data_found=1 t=${cached_hdd_temp[$d]} if (( t > max_h )); then max_h=$t max_h_dev=$d fi p_v=$(step_curve_pwm "$t" "$curve_str") (( p_v > cur_h_p )) && cur_h_p=$p_v fi done # Peak-Hold Logik HDD if (( cur_h_p > ${hdd_peak_pwm[$fan]:-0} )) || (( now - ${hdd_peak_time[$fan]:-0} > AFTER_PEAK_TEMP_COOLDOWN_HDD )); then hdd_peak_pwm[$fan]=$cur_h_p; hdd_peak_time[$fan]=$now fi pwm_h=${hdd_peak_pwm[$fan]} if (( max_h >= 0 )); then hdd_display="${max_h}°C (Peak:${pwm_h}%)" if (( pwm_h > final_speed )); then final_speed=$pwm_h final_driver="$max_h_dev=${max_h}°C(Peak)" fi else if [[ -n "${fan_disks[$fan]}" ]]; then hdd_display="(sleeping/cooldown)" fi fi ;; CPU) curve_str="${cpu_curve_map[$fan]}" [[ -z "$curve_str" ]] && continue p=$(step_curve_pwm "$cpu_temp" "$curve_str") if (( p > final_speed )); then final_speed=$p final_driver="CPU=${cpu_temp}°C" fi ;; NVME) curve_str="${nvme_curve_map[$fan]}" [[ -z "$curve_str" ]] && continue cur_p=0; cur_t=-1; cur_t_dev="" if [[ -n "${fan_nvmes[$fan]}" ]]; then for d in ${fan_nvmes[$fan]}; do if [[ -n "${nvme_time_current[$d]}" && $(( now - nvme_time_current[$d] )) -lt 60 ]]; then data_found=1 t=${nvme_temp_current[$d]} if (( t > cur_t )); then cur_t=$t cur_t_dev=$d fi p_v=$(step_curve_pwm "$t" "$curve_str") (( p_v > cur_p )) && cur_p=$p_v fi done # Peak-Hold Logik NVMe if (( cur_p > ${nvme_peak_pwm[$fan]:-0} )) || (( now - ${nvme_peak_time[$fan]:-0} > AFTER_PEAK_TEMP_COOLDOWN_NVME )); then nvme_peak_pwm[$fan]=$cur_p; nvme_peak_time[$fan]=$now fi pwm_n=${nvme_peak_pwm[$fan]} if [[ -n "$pwm_n" && "$pwm_n" -gt 0 ]]; then nvme_display="${cur_t}°C (Peak:${pwm_n}%)" if (( pwm_n > final_speed )); then final_speed=$pwm_n final_driver="$cur_t_dev=${cur_t}°C(Peak)" fi else nvme_display="(sleeping)" fi fi ;; TR1|TR2|TR3) t_val=${ipmi_temps[$src]} if [[ "$t_val" =~ ^[0-9] ]]; then t_int=${t_val%.*} case $src in TR1) curve_str="${tr1_curve_map[$fan]}" ;; TR2) curve_str="${tr2_curve_map[$fan]}" ;; TR3) curve_str="${tr3_curve_map[$fan]}" ;; esac [[ -z "$curve_str" ]] && continue p_now=$(step_curve_pwm "$t_int" "$curve_str") idx="${fan}_${src}" cooldown_ref="AFTER_PEAK_TEMP_COOLDOWN_$src" if (( p_now > ${tr_peak_pwm[$idx]:-0} )) || (( now - ${tr_peak_time[$idx]:-0} > ${!cooldown_ref} )); then tr_peak_pwm[$idx]=$p_now; tr_peak_time[$idx]=$now fi p_final=${tr_peak_pwm[$idx]} if (( p_final > final_speed )); then final_speed=$p_final final_driver="$src=${t_int}°C" fi tr_display+="$src:${t_int}°C(P:${p_final}%) " fi ;; esac done # --- Array Status Logik --- if [[ "$array_state" != "STARTED" ]]; then if [[ "$sources" =~ "HDD" || "$sources" =~ "NVME" ]]; then if (( data_found == 0 )); then s_pwm=${secure_pwm[$fan]} if [[ -n "$s_pwm" ]]; then final_speed=$s_pwm final_driver="SecureMode (Array Stopped)" fi fi fi fi # Falls nach allen Quellen final_speed immer noch 0 if (( final_speed == 0 )); then main_src=$(echo "$sources" | awk '{print $1}') case $main_src in HDD) base_curve="${hdd_curve_map[$fan]}" ;; CPU) base_curve="${cpu_curve_map[$fan]}" ;; NVME) base_curve="${nvme_curve_map[$fan]}" ;; *) base_curve="${cpu_curve_map[$fan]:-${hdd_curve_map[$fan]}}" ;; esac first_p=$(get_first_pwm_from_curve "$base_curve") final_speed=${first_p:-10} final_driver="Idle/Base" fi # Emergency Check emergency=0; emergency_reasons=() for d in "${!cached_hdd_temp[@]}"; do if [[ -n "${cached_hdd_time[$d]}" && $(( now - cached_hdd_time[$d] )) -lt $AFTER_ACTIVITY_COOLDOWN_HDD && ${cached_hdd_temp[$d]} -ge $MAX_SAFE_HDD_TEMP ]]; then emergency=1; emergency_reasons+=("HDD:$d") fi done for d in "${!nvme_temp_current[@]}"; do if [[ -n "${nvme_time_current[$d]}" && $(( now - nvme_time_current[$d] )) -lt 60 && ${nvme_temp_current[$d]} -ge $MAX_SAFE_NVME_TEMP ]]; then emergency=1; emergency_reasons+=("NVME:$d") fi done if (( cpu_temp >= MAX_SAFE_CPU_TEMP )); then emergency=1; emergency_reasons+=("CPU"); fi if (( emergency )); then final_speed=100 reasons_str=$(printf "%s\n" "${emergency_reasons[@]}" | sort -u | paste -sd ',' - | sed 's/,/, /g') log_indicator="EMERGENCY [$reasons_str]" else log_indicator="Target=${final_speed}%" fi # PWM Safety Cap (0-100) (( final_speed > 100 )) && final_speed=100 (( final_speed < 0 )) && final_speed=0 # Setzen & Loggen if [[ "$final_speed" -ne "${last_pwm[$fan]:--1}" || "$DRY_RUN" -eq 1 ]]; then last_pwm[$fan]="$final_speed" timestamp=$(date '+%F | %T') if (( emergency )); then log_msg="🚀 Set $fan | $log_indicator → Target=${final_speed}% | $timestamp" else log_msg="🚀 Set $fan | HDD=$hdd_display | NVMe=$nvme_display | CPU=${cpu_temp}°C" [[ -n "$tr_display" ]] && log_msg+=" | TR=$tr_display" log_msg+=" → $final_driver → $log_indicator | $timestamp" fi log_echo "$log_msg" if (( ! DRY_RUN )); then hex_pwm=$(printf '0x%02x' "$final_speed") if ! ipmi-raw 0x00 0x30 0x0e 0x04 "$zone_hex" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" > /dev/null 2>&1; then log_echo "⚠️ IPMI Error! Set Failsafe: $FAILSAFE_FAN_SPEED%" hex_fs=$(printf '0x%02x' "$FAILSAFE_FAN_SPEED") ipmi-raw 0x00 0x30 0x0e 0x04 "$zone_hex" 0x01 "$hex_fs" 0x01 "$hex_fs" 0x01 "$hex_fs" 0x01 "$hex_fs" 0x01 "$hex_fs" > /dev/null 2>&1 fi fi fi done sleep "$INTERVAL"doneFan_Control_Secure_Mode (at stopping of array):Fan_Control_Secure_Mode#!/bin/bash# Fan_Control_Secure_Mode# Only for ASUS Pro WS W680-ACE IPMI PCIe-CARD# Purpose: One-Shot execution at "At stopping of array" # ====================================# ⚙️ Sicherheits-Lüfterwerte# ====================================declare -A secure_pwmsecure_pwm["CHA_FAN1"]=59 # unten links HDDssecure_pwm["CHA_FAN2"]=59 # unten mitte HDDssecure_pwm["CHA_FAN3"]=59 # unten rechts HDDssecure_pwm["CHA_FAN4"]=60 # oben links MB & links hinten HBAsecure_pwm["CHA_FAN5"]=30 # oben mittesecure_pwm["CHA_FAN6"]=30 # oben rechts Richtung CPUsecure_pwm["CHA_FAN7"]=62 # hinten Gehäuseentlüftungsecure_pwm["CHA_FAN8"]=42 # CPU Kühler LOG_DIR="/tmp/user.scripts/tmpScripts/Fan_Control_Secure_Mode"LOGFILE="$LOG_DIR/log.txt" # Verzeichnis erstellen, falls nicht vorhandenmkdir -p "$LOG_DIR" log_echo() { timestamp=$(date '+%F | %T') echo "🛡️ [$timestamp] Secure Mode: $1" >> "$LOGFILE"} log_echo "Array stop detected. Setting fans to secure PWM values..."logger "Fan_Control_Secure_Mode: Array stop detected. Setting fans to secure PWM values..." # Schleife über alle 8 Lüfterfor i in {1..8}; do fan="CHA_FAN$i" pwm="${secure_pwm[$fan]}" if [[ -n "$pwm" ]]; then zone_hex=$(printf '0x%02x' $((i - 1))) hex_pwm=$(printf '0x%02x' "$pwm") # IPMI Befehl absetzen if ipmi-raw 0x00 0x30 0x0e 0x04 "$zone_hex" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" > /dev/null 2>&1; then log_echo "$fan set to ${pwm}%" else log_echo "❌ ERROR setting $fan" fi fidone log_echo "Fan Secure Mode values applied."logger "Fan_Control_Secure_Mode: Fan Secure Mode values applied."
November 4Nov 4 Hello enect, thank you for this awesome script, i do have an Asus Pro WS W880-ACE SE on a Jonsbo N5 too But i only use CHA_FAN1 and CHA_FAN2 for HDDs, CHA_FAN4 and CHA_FAN5 are only used to refresh CPU, HBA, GPU and NVME area, can you help me to modify the script to work on my configuration ? Edited November 4Nov 4 by doobyns
November 17Nov 17 On 11/4/2026 at 5:55 PM, doobyns said:Hello enect, thank you for this awesome script, i do have an Asus Pro WS W880-ACE SE on a Jonsbo N5 tooHi... The system here didn't ping me... so I'm only seeing the message today. Thanks for the feedback. I’ve developed the script significantly since then, and it now runs extremely robustly. Take a look and see if it’s self-explanatory—or try running it through an AI. Otherwise, feel free to ask your question, and I’ll do my best to answer. See Box... click details:Fan_Control#!/bin/bash# Fan_Control# Only for ASUS Pro WS W680-ACE IPMI PCIe-CARD# V1.22 - Production Ready / Final Candidate - 24.06.2026# Fixes: IPMI Log-Spam Schutz, 5-Minuten-Schutzzeit für NVMe-Emergency,# Vollständige Absicherung aller ipmi-raw Befehle mit timeout 5.# PMI-Timeout-Warning hinzugefügt, NVMe Peak-Hold Logik validiert.# Dynamic Array-State (STARTING-Schutz), NVMe Activity-Timeout entfernt, Befehl mit 5s-Timeout gehärtet.# Array-State auf dezidiertes STOPPED geändert, NVMe-Symmetrie-GC, Beseitigung des log_indicator Leaks im Fan-Loop.# CPU-Temperatur-Historie statt PWM-Fallback, konsistenter Slot/Temp-Drop,# Sicherer mdState-Check, optimierter globaler Emergency-Check außerhalb der Fan-Schleife.# Slot-Verwurf bei leerem Unraid-Slot, CPU-Sensors Fallback, # Scharfschaltung der TRx-Emergency-Grenzwerte und final_driver NVMe-Peak Textfix.# Korrekte Assoziative Array Resets, vollständige HDD & NVMe GC über die Slots/Devices,# Beseitigung des -1°C NVMe Log-Bugs und IPMI-Sensor-Ghosting-Schutz.# Fix V1.15: Sauberer unset für seen_hdds & sofortiges Verwerfen von Cache-Werten bei Slot-Wechsel auf gleicher sdX.# Fix V1.14: Dynamische Garbage Collection für physisch entfernte HDDs.# Fix V1.13: Striktes Parity-Matching. parity matcht nur noch parity, parity2 muss explizit definiert werden.# Fix V1.12: Expliziter Ausschluss der "flash" Sektion im disks.ini Parser.# =======================# ⚙️ Globale Einstellungen# =======================INTERVAL=5 # Intervall in Sekunden für SchleifendurchlaufDRY_RUN=0 # 1 = Testmodus (kein IPMI-Befehl), 0 = aktivFAILSAFE_FAN_SPEED=60 # Notfallgeschwindigkeit bei IPMI-FehlerAFTER_ACTIVITY_COOLDOWN_HDD=900 # Zeit (Sekunden), Unraid legt HDDs schlafenAFTER_PEAK_TEMP_COOLDOWN_HDD=300 # Zeit (Sekunden), Peak-Hold HDDAFTER_PEAK_TEMP_COOLDOWN_NVME=180 # Zeit (Sekunden), Peak-Hold NVMe# Individuelle Peak-Cooldowns für TR-SensorenAFTER_PEAK_TEMP_COOLDOWN_TR1=180 # RAM CooldownAFTER_PEAK_TEMP_COOLDOWN_TR2=180 # HBA CooldownAFTER_PEAK_TEMP_COOLDOWN_TR3=180 # GPU CooldownMAX_SAFE_HDD_TEMP=53 # Temperaturgrenze HDDs → Failsafe 100%MAX_SAFE_NVME_TEMP=80 # Temperaturgrenze NVMe → Failsafe 100%MAX_SAFE_CPU_TEMP=95 # Temperaturgrenze CPU → Failsafe 100%# Individuelle Max-Safe-Temperaturen für TR-SensorenMAX_SAFE_TR1_TEMP=65 # RAM MaxMAX_SAFE_TR2_TEMP=75 # HBA MaxMAX_SAFE_TR3_TEMP=85 # GPU MaxLOGFILE="/tmp/user.scripts/tmpScripts/Fan_Control/log.txt"# ====================================# ⚙️ Sicherheits-Lüfterwerte (NUR wenn Array NICHT aktiv/startend ist)# ====================================declare -A secure_pwmsecure_pwm["CHA_FAN1"]=59 # unten links HDDssecure_pwm["CHA_FAN2"]=59 # unten mitte HDDssecure_pwm["CHA_FAN3"]=59 # unten rechts HDDssecure_pwm["CHA_FAN4"]=60 # oben links MB & links hinten HBAsecure_pwm["CHA_FAN5"]=30 # oben mittesecure_pwm["CHA_FAN6"]=30 # oben rechts Richtung CPUsecure_pwm["CHA_FAN7"]=62 # hinten Gehäuseentlüftungsecure_pwm["CHA_FAN8"]=42 # CPU Kühler# ====================================# 🔍 Preflight: benötigte Tools prüfen# ====================================missing_tools=()for cmd in sensors ipmi-raw ipmi-sensors awk timeout; doif ! command -v "$cmd" >/dev/null 2>&1; thenmissing_tools+=("$cmd")fidoneif (( ${#missing_tools[@]} > 0 )); thentimestamp=$(date '+%F | %T')echo "❌ [$timestamp] Missing required tools: ${missing_tools[*]}" >> "$LOGFILE"exit 1fi# ====================================# 🧭 Steuerlogik je CHA_FANx (1–8)# ====================================declare -A fan_sourcesfan_sources["CHA_FAN1"]="HDD" # unten links HDDsfan_sources["CHA_FAN2"]="HDD" # unten mitte HDDsfan_sources["CHA_FAN3"]="HDD" # unten rechts HDDsfan_sources["CHA_FAN4"]="HDD CPU NVME TR2 TR3" # oben links MB & links hinten HBAfan_sources["CHA_FAN5"]="CPU NVME TR3" # oben mittefan_sources["CHA_FAN6"]="CPU TR1 TR3" # oben rechts Richtung CPUfan_sources["CHA_FAN7"]="HDD CPU NVME TR1 TR3" # hinten Gehäuseentlüftungfan_sources["CHA_FAN8"]="CPU" # CPU Kühler# ====================================# 💾 Device-Zuordnungen# ====================================declare -A fan_disksfan_disks["CHA_FAN1"]="ALL_HDDS" # Möglichkeiten:fan_disks["CHA_FAN2"]="ALL_HDDS" # einzeln aufzählen: "parity parity2 disk1 disk8"fan_disks["CHA_FAN3"]="ALL_HDDS" # Gruppen: "disk[1-12]fan_disks["CHA_FAN4"]="ALL_HDDS" # alle HDDS: "ALL_HDDS"fan_disks["CHA_FAN7"]="ALL_HDDS" # Mix: "parity parity2 disk[1-12]"declare -A fan_nvmesfan_nvmes["CHA_FAN4"]="nvme0n1 nvme1n1 nvme2n1"fan_nvmes["CHA_FAN5"]="nvme0n1 nvme1n1 nvme2n1"fan_nvmes["CHA_FAN7"]="nvme0n1 nvme1n1 nvme2n1"# ====================================# 📈 Kurven-Definitionen# ====================================declare -A hdd_curve_maphdd_curve_map["CHA_FAN1"]="1=25 40=59 45=70 50=90 55=100"hdd_curve_map["CHA_FAN2"]="1=25 40=59 45=70 50=90 55=100"hdd_curve_map["CHA_FAN3"]="1=25 40=59 45=70 50=90 55=100"hdd_curve_map["CHA_FAN4"]="1=30 30=50 40=60 45=72 55=85"hdd_curve_map["CHA_FAN5"]="1=30 40=50 45=70 50=90 55=100"hdd_curve_map["CHA_FAN6"]="1=30 40=50 45=70 50=90 55=100"hdd_curve_map["CHA_FAN7"]="1=30 30=52 40=62 45=72 55=100"hdd_curve_map["CHA_FAN8"]="1=42 40=50 45=70 50=90 55=100"declare -A nvme_curve_mapnvme_curve_map["CHA_FAN4"]="1=30 45=50 50=60 70=90 80=100"nvme_curve_map["CHA_FAN5"]="1=30 45=50 50=60 70=90 80=100"nvme_curve_map["CHA_FAN7"]="1=30 45=62 60=72 70=90 80=100"declare -A cpu_curve_mapcpu_curve_map["CHA_FAN1"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN2"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN3"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN4"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN5"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN6"]="1=30 75=50 80=70 90=90 95=100"cpu_curve_map["CHA_FAN7"]="1=30 75=62 80=70 90=90 95=100"cpu_curve_map["CHA_FAN8"]="1=42 75=50 80=80 90=90 95=100"declare -A tr1_curve_map # RAMtr1_curve_map["CHA_FAN6"]="1=30 45=49 55=60 60=80 65=100"tr1_curve_map["CHA_FAN7"]="1=30 45=62 55=72 60=90 65=100"declare -A tr2_curve_map # HBAtr2_curve_map["CHA_FAN4"]="1=30 50=50 60=75 65=90 70=100"declare -A tr3_curve_map # GPUtr3_curve_map["CHA_FAN4"]="1=30 50=50 60=65 70=85 80=100"tr3_curve_map["CHA_FAN5"]="1=30 50=50 60=65 70=85 80=100"tr3_curve_map["CHA_FAN6"]="1=30 50=50 60=65 70=85 80=100"tr3_curve_map["CHA_FAN7"]="1=30 50=62 60=65 70=85 80=100"# ====================================# 🧠 Zustands-Tracking & Helfer# ====================================declare -A last_pwm cached_hdd_temp cached_hdd_time nvme_temp_current nvme_time_current declare -A hdd_peak_pwm hdd_peak_time nvme_peak_pwm nvme_peak_time ipmi_tempsdeclare -A tr_peak_pwm tr_peak_time warned_missing_curvedeclare -A cached_hdd_slot nvme_devices_seen declare -A seen_hdds seen_nvmes ipmi_warning_logged last_cpu_temp=45 log_echo() {echo "$1" >> "$LOGFILE"[[ $(wc -l < "$LOGFILE" 2>/dev/null) -gt 150 ]] && tail -n 100 "$LOGFILE" > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"}step_curve_pwm() {local temp=$1 curve_string=$2 last_p=0[[ -z "$curve_string" ]] && echo 0 && returnfor pair in $curve_string; dolocal t="${pair%=*}" pwm="${pair#*=}"(( temp < t )) && echo "$last_p" && returnlast_p=$pwmdoneecho "$last_p"}get_first_pwm_from_curve() {for pair in $1; do echo "${pair#*=}"; return; doneecho 10}# ====================# 🔁 Hauptschleife# ====================while true; donow=$(date +%s)log_indicator="" # --- Array Status Check ---array_state=$(grep "mdState=" /var/local/emhttp/var.ini | cut -d'"' -f2)# 1. CPU Temp mit echtem Historien-Fallbackcpu_temp=$(sensors 2>/dev/null | awk '/Package id 0:/ {print int($4)}' | head -n1)if [[ "$cpu_temp" =~ ^[0-9]+$ ]]; thenlast_cpu_temp=$cpu_tempelsecpu_temp=$last_cpu_tempfi# 2. IPMI-Sensoren Snapshotipmi_temps=()while read -r line; doname=$(echo "$line" | cut -d'|' -f2 | xargs)val=$(echo "$line" | cut -d'|' -f5 | xargs)case "$name" in"TR1 Temperature") ipmi_temps["TR1"]=$val ;;"TR2 Temperature") ipmi_temps["TR2"]=$val ;;"TR3 Temperature") ipmi_temps["TR3"]=$val ;;esacdone < <(timeout 5 ipmi-sensors --quiet-cache --output-sensor-state --sensor-types Temperature 2>/dev/null)# Fix: IPMI Log-Spam Schutz via Flag-Handlingif (( ${#ipmi_temps[@]} == 0 )); thenif [[ -z "${ipmi_warning_logged[failed]}" ]]; thentimestamp_err=$(date '+%F | %T')log_echo "⚠️ [$timestamp_err] IPMI Temperature read timeout/failed - global curves still active"ipmi_warning_logged[failed]=1fielseunset "ipmi_warning_logged[failed]"fi# 3. HDD & NVMe Scan via disks.iniseen_hdds=()seen_nvmes=()while IFS='|' read -r dev temp spun status slot; doif [[ -n "$dev" ]]; thenif [[ "$dev" == sd* ]]; thenseen_hdds[$dev]=1 if [[ -n "$slot" ]]; thenif [[ -n "${cached_hdd_slot[$dev]}" && "${cached_hdd_slot[$dev]}" != "$slot" ]]; thenunset "cached_hdd_temp[$dev]"unset "cached_hdd_time[$dev]"ficached_hdd_slot[$dev]=$slotelseunset "cached_hdd_slot[$dev]"unset "cached_hdd_temp[$dev]"unset "cached_hdd_time[$dev]"fiif [[ "$spun" == "0" && "$temp" =~ ^[0-9]+$ ]]; thencached_hdd_temp[$dev]=$tempcached_hdd_time[$dev]=$nowfielif [[ "$dev" == nvme* ]]; thenseen_nvmes[$dev]=1 nvme_devices_seen[$dev]=1 if [[ "$temp" =~ ^[0-9]+$ ]]; thennvme_temp_current[$dev]=$tempnvme_time_current[$dev]=$nowfififidone < <(awk -F'=' 'function flush() {if (dev != "" && current_section != "flash") {print dev "|" temp "|" spun "|" stat "|" slot}}{gsub(/["\]]/, "", $0)if ($0 ~ /^\[/) {gsub(/[\[]/, "", $0)current_section = $0}else if ($1 == "device") {flush()dev = $2gsub(/[", ]/, "", dev)slot = current_sectiontemp=""; spun=""; stat=""}else if ($1 == "temp") { gsub(/[", ]/, "", $2); temp = $2 }else if ($1 == "spundown") { gsub(/[", ]/, "", $2); spun = $2 }else if ($1 == "status") { gsub(/[", ]/, "", $2); stat = $2 }}END { flush() }' /var/local/emhttp/disks.ini)# 4. Garbage Collectionfor d in "${!cached_hdd_slot[@]}"; doif [[ -z "${seen_hdds[$d]}" ]]; thenunset "cached_hdd_temp[$d]"unset "cached_hdd_time[$d]"unset "cached_hdd_slot[$d]"fidonefor d in "${!nvme_devices_seen[@]}"; doif [[ -z "${seen_nvmes[$d]}" ]]; thenunset "nvme_temp_current[$d]"unset "nvme_time_current[$d]"unset "nvme_devices_seen[$d]"fidone# --- 📊 Zentraler Globaler Emergency Check ---emergency=0emergency_reasons=()for d in "${!cached_hdd_temp[@]}"; doif [[ -n "${cached_hdd_time[$d]}" && $(( now - cached_hdd_time[$d] )) -lt $AFTER_ACTIVITY_COOLDOWN_HDD && ${cached_hdd_temp[$d]} -ge $MAX_SAFE_HDD_TEMP ]]; thensname="${cached_hdd_slot[$d]:-$d}"emergency=1; emergency_reasons+=("HDD:$sname")fidonefor d in "${!nvme_temp_current[@]}"; do# Fix: 5-Minuten-Zeitpuffer (300s) gegen eingefrorene/tote NVMe-Sensoren im Emergency-Zweigif [[ -n "${nvme_time_current[$d]}" && $(( now - nvme_time_current[$d] )) -lt 300 && ${nvme_temp_current[$d]} -ge $MAX_SAFE_NVME_TEMP ]]; thenemergency=1; emergency_reasons+=("NVME:$d")fidoneif (( cpu_temp >= MAX_SAFE_CPU_TEMP )); then emergency=1; emergency_reasons+=("CPU")fiif [[ "${ipmi_temps[TR1]}" =~ ^[0-9]+$ ]]; thent_tr1=${ipmi_temps[TR1]%.*}; if (( t_tr1 >= MAX_SAFE_TR1_TEMP )); then emergency=1; emergency_reasons+=("TR1(RAM)"); fifiif [[ "${ipmi_temps[TR2]}" =~ ^[0-9]+$ ]]; thent_tr2=${ipmi_temps[TR2]%.*}; if (( t_tr2 >= MAX_SAFE_TR2_TEMP )); then emergency=1; emergency_reasons+=("TR2(HBA)"); fifiif [[ "${ipmi_temps[TR3]}" =~ ^[0-9]+$ ]]; thent_tr3=${ipmi_temps[TR3]%.*}; if (( t_tr3 >= MAX_SAFE_TR3_TEMP )); then emergency=1; emergency_reasons+=("TR3(GPU)"); fifiif (( emergency )); thenreasons_str=$(printf "%s\n" "${emergency_reasons[@]}" | sort -u | paste -sd ',' - | sed 's/,/, /g')log_indicator="EMERGENCY [$reasons_str]"fi# 5. Fan-Loopfor i in {1..8}; dofan="CHA_FAN$i"; sources="${fan_sources[$fan]}"[[ -z "$sources" ]] && continuefinal_speed=0final_driver=""data_found=0hdd_display="(not used)"; nvme_display="(not used)"; tr_display=""zone_hex=$(printf '0x%02x' $((i - 1)))for src in $sources; docase $src inHDD)curve_str="${hdd_curve_map[$fan]}"[[ -z "$curve_str" ]] && continuecur_h_p=0; max_h=-1; max_h_dev=""for d in "${!cached_hdd_temp[@]}"; dosname="${cached_hdd_slot[$d]}"[[ -z "$sname" ]] && continuematch=0for pattern in ${fan_disks[$fan]}; doif [[ "$pattern" == "ALL_HDDS" ]]; thenmatch=1breakelif [[ "$pattern" =~ ^disk\[([0-9]+)-([0-9]+)\]$ ]]; thenstart_range="${BASH_REMATCH[1]}"end_range="${BASH_REMATCH[2]}"if [[ "$sname" =~ ^disk([0-9]+)$ ]]; thendisk_num="${BASH_REMATCH[1]}"if (( disk_num >= start_range && disk_num <= end_range )); thenmatch=1breakfifielif [[ "$sname" == "$pattern" ]]; thenmatch=1breakfidoneif (( match )); thenif [[ -n "${cached_hdd_time[$d]}" && $(( now - cached_hdd_time[$d] )) -lt $AFTER_ACTIVITY_COOLDOWN_HDD ]]; thendata_found=1t=${cached_hdd_temp[$d]}if (( t > max_h )); thenmax_h=$tmax_h_dev="$sname($d)"fip_v=$(step_curve_pwm "$t" "$curve_str")(( p_v > cur_h_p )) && cur_h_p=$p_vfifidoneif (( cur_h_p > ${hdd_peak_pwm[$fan]:-0} )) || (( now - ${hdd_peak_time[$fan]:-0} > AFTER_PEAK_TEMP_COOLDOWN_HDD )); thenhdd_peak_pwm[$fan]=$cur_h_p; hdd_peak_time[$fan]=$nowfipwm_h=${hdd_peak_pwm[$fan]}if (( max_h >= 0 )); thenhdd_display="${max_h}°C (Peak:${pwm_h}%)"if (( pwm_h > final_speed )); thenfinal_speed=$pwm_hfinal_driver="$max_h_dev=${max_h}°C(Peak)"fielseif [[ -n "${fan_disks[$fan]}" ]]; thenhdd_display="(sleeping/cooldown)"fifi;;CPU)curve_str="${cpu_curve_map[$fan]}"[[ -z "$curve_str" ]] && continuep=$(step_curve_pwm "$cpu_temp" "$curve_str")if (( p > final_speed )); thenfinal_speed=$pfinal_driver="CPU=${cpu_temp}°C"fi;;NVME)curve_str="${nvme_curve_map[$fan]}"[[ -z "$curve_str" ]] && continuecur_p=0; cur_t=-1; cur_t_dev=""if [[ -n "${fan_nvmes[$fan]}" ]]; thenfor d in ${fan_nvmes[$fan]}; doif [[ -n "${nvme_temp_current[$d]}" ]]; thendata_found=1t=${nvme_temp_current[$d]}if (( t > cur_t )); thencur_t=$tcur_t_dev=$dfip_v=$(step_curve_pwm "$t" "$curve_str")(( p_v > cur_p )) && cur_p=$p_vfidoneif (( cur_p > ${nvme_peak_pwm[$fan]:-0} )) || (( now - ${nvme_peak_time[$fan]:-0} > AFTER_PEAK_TEMP_COOLDOWN_NVME )); thennvme_peak_pwm[$fan]=$cur_p; nvme_peak_time[$fan]=$nowfipwm_n=${nvme_peak_pwm[$fan]}if [[ -n "$pwm_n" && "$pwm_n" -gt 0 ]]; thenif (( cur_t >= 0 )); thennvme_display="${cur_t}°C (Peak:${pwm_n}%)"if (( pwm_n > final_speed )); thenfinal_speed=$pwm_nfinal_driver="$cur_t_dev=${cur_t}°C(Peak)"fielsenvme_display="(sleeping/cooldown Peak:${pwm_n}%)"if (( pwm_n > final_speed )); thenfinal_speed=$pwm_nfinal_driver="NVMe Peak-Hold"fifielsenvme_display="(sleeping)"fifi;;TR1|TR2|TR3)t_val=${ipmi_temps[$src]}if [[ "$t_val" =~ ^[0-9]+$ ]]; thent_int=${t_val%.*}case $src inTR1) curve_str="${tr1_curve_map[$fan]}" ;;TR2) curve_str="${tr2_curve_map[$fan]}" ;;TR3) curve_str="${tr3_curve_map[$fan]}" ;;esac[[ -z "$curve_str" ]] && continuep_now=$(step_curve_pwm "$t_int" "$curve_str")idx="${fan}_${src}"cooldown_ref="AFTER_PEAK_TEMP_COOLDOWN_$src"if (( p_now > ${tr_peak_pwm[$idx]:-0} )) || (( now - ${tr_peak_time[$idx]:-0} > ${!cooldown_ref} )); thentr_peak_pwm[$idx]=$p_now; tr_peak_time[$idx]=$nowfip_final=${tr_peak_pwm[$idx]}if (( p_final > final_speed )); thenfinal_speed=$p_finalfinal_driver="$src=${t_int}°C"fitr_display+="$src:${t_int}°C(P:${p_final}%) "fi;;esacdone# --- Array Status Logik ---if [[ "$array_state" != "STARTED" && "$array_state" != "STARTING" ]]; thenif [[ "$sources" =~ "HDD" || "$sources" =~ "NVME" ]]; thenif (( data_found == 0 )); thens_pwm=${secure_pwm[$fan]}if [[ -n "$s_pwm" ]]; thenfinal_speed=$s_pwmfinal_driver="SecureMode (Array Stopped)"fifififiif (( final_speed == 0 )); thenmain_src=$(echo "$sources" | awk '{print $1}')case $main_src inHDD) base_curve="${hdd_curve_map[$fan]}" ;;CPU) base_curve="${cpu_curve_map[$fan]}" ;;NVME) base_curve="${nvme_curve_map[$fan]}" ;;*) base_curve="${cpu_curve_map[$fan]:-${hdd_curve_map[$fan]}}" ;;esacfirst_p=$(get_first_pwm_from_curve "$base_curve")final_speed=${first_p:-10}final_driver="Idle/Base"fi# Globalen Emergency Status anwendenif (( emergency )); then final_speed=100elselog_indicator="Target=${final_speed}%"fi(( final_speed > 100 )) && final_speed=100(( final_speed < 0 )) && final_speed=0if [[ "$final_speed" -ne "${last_pwm[$fan]:--1}" || "$DRY_RUN" -eq 1 ]]; thenlast_pwm[$fan]="$final_speed"timestamp=$(date '+%F | %T')if (( emergency )); thenlog_msg="🚀 Set $fan | $log_indicator → Target=${final_speed}% | $timestamp"elselog_msg="🚀 Set $fan | HDD=$hdd_display | NVMe=$nvme_display | CPU=${cpu_temp}°C"[[ -n "$tr_display" ]] && log_msg+=" | TR=$tr_display"log_msg+=" || $final_driver → $log_indicator | $timestamp"filog_echo "$log_msg"if (( ! DRY_RUN )); thenhex_pwm=$(printf '0x%02x' "$final_speed")# Fix: Beide ipmi-raw Befehle mit timeout 5 gegen komplette Blockade bei BMC-Freeze gehärtetif ! timeout 5 ipmi-raw 0x00 0x30 0x0e 0x04 "$zone_hex" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" 0x01 "$hex_pwm" > /dev/null 2>&1; thenlog_echo "⚠️ IPMI Error! Set Failsafe: $FAILSAFE_FAN_SPEED%"hex_fs=$(printf '0x%02x' "$FAILSAFE_FAN_SPEED")timeout 5 ipmi-raw 0x00 0x30 0x0e 0x04 "$zone_hex" 0x01 "$hex_fs" 0x01 "$hex_fs" 0x01 "$hex_fs" 0x01 "$hex_fs" 0x01 "$hex_fs" > /dev/null 2>&1fififidonesleep "$INTERVAL"done Edited November 17Nov 17 by enect
Monday at 07:39 PM4 days Thanks Enect, i tried your script but i don't have an IPMI PCIe-CARD, so i used the ideas used in your script and made one with ai which works without IPMI PCIe-CARD, it's the first version but it's work, i share it for other folks with an ASUS Pro WS W680-ACE without IPMI PCIe-CARD :# ASUS Pro WS W680-ACE — CPU / HDD / NVMe# Zones IPMI confirmées par l'utilisateur :# CHA_FAN1 logique (0x00) -> CPU_FAN physique# CHA_FAN2 logique (0x01) -> CHA_FAN1 physique (HDD)# CHA_FAN3 logique (0x02) -> CHA_FAN2 physique (HDD)# CHA_FAN4 logique (0x03) -> CHA_FAN3 physique : UNUSED, aucune commande# CHA_FAN5 logique (0x04) -> CHA_FAN4 physique (NVMe)# CHA_FAN6 logique (0x05) -> CHA_FAN5 physique (NVMe)# CHA_FAN7 logique (0x06) -> UNUSED, aucune commande# CHA_FAN8 logique (0x07) -> UNUSED, aucune commandeINTERVAL=5DRY_RUN=0 # Mettre 0 seulement après vérificationFAILSAFE_PWM=100CPU_LIMIT=95HDD_LIMIT=53NVME_LIMIT=80HDD_CACHE_SECONDS=900HDD_HOLD_SECONDS=300NVME_CACHE_SECONDS=60NVME_HOLD_SECONDS=180TEMP_LOG_INTERVAL=60LOG_EVERY_CYCLE=0DISKS_INI="/var/local/emhttp/disks.ini"LOGFILE="/tmp/Fan_Control_CPU_HDD_NVME.log"HDD_DEVICES="sdc sdd sdk sdg sdj sdi sda sdf sde sdh"NVME_DEVICES="nvme0n1 nvme1n1 nvme2n1"# Une zone IPMI n'est pas nécessairement le même numéro que le connecteur physique.declare -A FAN_SOURCE=([1]=CPU [2]=HDD [3]=HDD [4]=UNUSED [5]=NVME [6]=NVME [7]=UNUSED [8]=UNUSED)declare -A last_pwm disk_temp disk_seen nvme_temp nvme_seenhdd_hold_pwm=0; hdd_hold_until=0nvme_hold_pwm=0; nvme_hold_until=0last_temp_log=0log_context=""log() { local msg msg="$(date '+%F %T') | $*" printf '%s\n' "$msg" printf '%s\n' "$msg" >> "$LOGFILE" || printf 'Ecriture log impossible : %s\n' "$LOGFILE" >&2}cpu_pwm() { local t=$1 if (( t >= 90 )); then echo 100 elif (( t >= 80 )); then echo 90 elif (( t >= 70 )); then echo 75 elif (( t >= 60 )); then echo 65 elif (( t >= 50 )); then echo 55 else echo 45 fi}hdd_pwm() { local t=$1 if (( t >= 55 )); then echo 100 elif (( t >= 50 )); then echo 89 elif (( t >= 45 )); then echo 79 elif (( t >= 43 )); then echo 69 elif (( t >= 40 )); then echo 45 else echo 30 fi}nvme_pwm() { local t=$1 if (( t >= 80 )); then echo 100 elif (( t >= 70 )); then echo 90 elif (( t >= 60 )); then echo 75 elif (( t >= 50 )); then echo 66 elif (( t >= 45 )); then echo 50 else echo 30 fi}# Lire en une fois les capteurs IPMI. Ne pas ajouter --output-sensor-state :# cette option décale la colonne Reading.read_ipmi() { ipmi-sensors --quiet-cache 2>/dev/null | awk -F'|' ' function trim(s) { gsub(/^[[:space:]]+|[[:space:]]+$/, "", s); return s } { name=trim($2); type=trim($3); val=trim($4) if (name=="CPU Package Temp" && type=="Temperature" && val ~ /^[0-9]+([.][0-9]+)?$/) print "TEMP|" int(val) if (type=="Fan" && name ~ /^(CPU_FAN|CHA_FAN[1-5])$/ && val ~ /^[0-9]+([.][0-9]+)?$/) print "FAN|" name "|" int(val) } '}# Lire les températures HDD et NVMe depuis disks.ini, comme dans le script original.# Si un NVMe n'y apparaît pas, un repli via nvme-cli est tenté plus bas.read_disks_ini() { local now=$1 dev temp spun [[ -r "$DISKS_INI" ]] || return 1 while IFS='|' read -r dev temp spun; do [[ "$temp" =~ ^[0-9]+$ ]] || continue if [[ " $HDD_DEVICES " " $dev " && "$spun" 0 ]]; then disk_temp["$dev"]=$temp; disk_seen["$dev"]=$now elif [[ " $NVME_DEVICES " == " $dev " ]]; then nvme_temp["$dev"]=$temp; nvme_seen["$dev"]=$now fi done < <(awk -F'=' ' function emit() { if (dev!="") print dev "|" temp "|" spun } { gsub(/["\[\],[:space:]]/, "", $0) if ($1=="device") { emit(); dev=$2; temp=""; spun="" } else if ($1=="temp") temp=$2 else if ($1=="spundown") spun=$2 } END { emit() } ' "$DISKS_INI")}# Repli NVMe direct, notamment pour les périphériques absents de disks.ini.# nvme smart-log expose "temperature : 40 C" ou une valeur Kelvin selon version.read_nvme_cli() { local now=$1 dev line t raw command -v nvme >/dev/null 2>&1 || return 0 for dev in $NVME_DEVICES; do [[ -e "/dev/$dev" ]] || continue line=$(nvme smart-log "/dev/$dev" 2>/dev/null | awk -F: 'tolower($1) ~ /^[[:space:]]*temperature[[:space:]]*$/ {print $2; exit}') [[ -n "$line" ]] || continue raw=$(printf '%s\n' "$line" | grep -oE '[0-9]+' | head -n1) [[ "$raw" =~ ^[0-9]+$ ]] || continue t=$raw # Certaines versions fournissent la température en Kelvin. (( t > 200 )) && t=$((t - 273)) if (( t >= 0 && t <= 125 )); then nvme_temp["$dev"]=$t; nvme_seen["$dev"]=$now fi done}send_pwm() { local fan=$1 pwm=$2 zone hex [[ "${last_pwm[$fan]:--1}" == "$pwm" ]] && return 0 log "${log_context}$( (( DRY_RUN )) && printf ' | TEST')" (( DRY_RUN )) && return 0 printf -v zone '0x%02x' "$((fan-1))" printf -v hex '0x%02x' "$pwm" if ipmi-raw 0x00 0x30 0x0e 0x04 "$zone" \ 0x01 "$hex" 0x01 "$hex" 0x01 "$hex" 0x01 "$hex" 0x01 "$hex" >/dev/null 2>&1; then last_pwm[$fan]=$pwm else log "ERREUR IPMI zone CHA_FAN${fan}, tentative secours ${FAILSAFE_PWM}%" printf -v hex '0x%02x' "$FAILSAFE_PWM" ipmi-raw 0x00 0x30 0x0e 0x04 "$zone" \ 0x01 "$hex" 0x01 "$hex" 0x01 "$hex" 0x01 "$hex" 0x01 "$hex" >/dev/null 2>&1 || \ log "ECHEC secours IPMI zone CHA_FAN${fan}" unset 'last_pwm[$fan]' fi}for cmd in awk ipmi-sensors ipmi-raw sensors; do if ! command -v "$cmd" >/dev/null 2>&1; then log "Outil manquant : $cmd"; exit 1; fidonelog "Démarrage | DRY_RUN=$DRY_RUN | nvme-cli=$(command -v nvme || echo absent)"log "Zones IPMI UNUSED : 0x03 (CHA_FAN3 physique), 0x06 (CHA_FAN7 logique), 0x07 (CHA_FAN8 logique)"log "IPMI : 0=CPU_FAN, 1=CHA_FAN1 HDD, 2=CHA_FAN2 HDD, 3=UNUSED, 4=CHA_FAN4 NVMe, 5=CHA_FAN5 NVMe, 6=UNUSED, 7=UNUSED"while true; do now=$(date +%s) cpu="" declare -A rpms=() while IFS='|' read -r kind name value; do if [[ "$kind" == TEMP ]]; then cpu=$name elif [[ "$kind" == FAN ]]; then rpms["$name"]=$value fi done < <(read_ipmi) # Repli lm-sensors si CPU absent dans IPMI if [[ ! "$cpu" =~ ^[0-9]+$ ]]; then cpu=$(sensors 2>/dev/null | awk ' /Package id 0:/ { pkg=$4 } /CPU Temp:/ { cpu=$3 } END { v=(pkg!="" ? pkg : cpu); if (v ~ /^\+?[0-9]+([.][0-9]+)?/) print int(v) } ') fi disks_ok=1 read_disks_ini "$now" || disks_ok=0 read_nvme_cli "$now" hottest_hdd=-1; hottest_hdd_dev="" for dev in $HDD_DEVICES; do if [[ -n "${disk_seen[$dev]:-}" ]] && (( now - disk_seen[$dev] < HDD_CACHE_SECONDS )); then t=${disk_temp[$dev]} if (( t > hottest_hdd )); then hottest_hdd=$t; hottest_hdd_dev=$dev; fi fi done hottest_nvme=-1; hottest_nvme_dev="" for dev in $NVME_DEVICES; do if [[ -n "${nvme_seen[$dev]:-}" ]] && (( now - nvme_seen[$dev] < NVME_CACHE_SECONDS )); then t=${nvme_temp[$dev]} if (( t > hottest_nvme )); then hottest_nvme=$t; hottest_nvme_dev=$dev; fi fi done target_hdd=36 (( hottest_hdd >= 0 )) && target_hdd=$(hdd_pwm "$hottest_hdd") if (( target_hdd > hdd_hold_pwm )); then hdd_hold_pwm=$target_hdd; hdd_hold_until=$((now+HDD_HOLD_SECONDS)) elif (( now >= hdd_hold_until )); then hdd_hold_pwm=$target_hdd; fi (( hdd_hold_pwm > target_hdd )) && target_hdd=$hdd_hold_pwm target_nvme=30 (( hottest_nvme >= 0 )) && target_nvme=$(nvme_pwm "$hottest_nvme") if (( target_nvme > nvme_hold_pwm )); then nvme_hold_pwm=$target_nvme; nvme_hold_until=$((now+NVME_HOLD_SECONDS)) elif (( now >= nvme_hold_until )); then nvme_hold_pwm=$target_nvme; fi (( nvme_hold_pwm > target_nvme )) && target_nvme=$nvme_hold_pwm emergency=0; reasons="" if [[ ! "$cpu" =~ ^[0-9]+$ ]]; then emergency=1; reasons+=" CPU_SENSOR_ABSENT"; fi if (( ! disks_ok )); then emergency=1; reasons+=" DISKS_INI_ABSENT"; fi if (( hottest_nvme < 0 )); then emergency=1; reasons+=" NVME_SENSOR_ABSENT"; fi if [[ "$cpu" =~ ^[0-9]+$ ]] && (( cpu >= CPU_LIMIT )); then emergency=1; reasons+=" CPU_CHAUD"; fi if (( hottest_hdd >= HDD_LIMIT )); then emergency=1; reasons+=" HDD_CHAUD"; fi if (( hottest_nvme >= NVME_LIMIT )); then emergency=1; reasons+=" NVME_CHAUD"; fi if (( emergency )); then target_cpu=$FAILSAFE_PWM; target_hdd=$FAILSAFE_PWM; target_nvme=$FAILSAFE_PWM else target_cpu=$(cpu_pwm "$cpu") fi cpu_label="${cpu:-N/A}°C" [[ "$cpu" =~ ^[0-9]+$ ]] || cpu_label="N/A" hdd_label="N/A"; (( hottest_hdd >= 0 )) && hdd_label="${hottest_hdd}°C" nvme_label="N/A"; (( hottest_nvme >= 0 )) && nvme_label="${hottest_nvme}°C" rpm_label=" | RPM: " for f in CPU_FAN CHA_FAN1 CHA_FAN2 CHA_FAN3 CHA_FAN4 CHA_FAN5; do rpm_label+=" ${f}=${rpms[$f]:-N/A}" done log_context="CPU=$cpu_label | HDD_max=$hdd_label | NVMe_max=$nvme_label${rpm_label}" if (( LOG_EVERY_CYCLE || now-last_temp_log >= TEMP_LOG_INTERVAL )); then log "TEMP | $log_context | Urgence=$emergency${reasons}" last_temp_log=$now fi for fan in 1 2 3 5 6; do case ${FAN_SOURCE[$fan]} in CPU) send_pwm "$fan" "$target_cpu" ;; HDD) send_pwm "$fan" "$target_hdd" ;; NVME) send_pwm "$fan" "$target_nvme" ;; UNUSED) : ;; # Ne jamais envoyer de commande IPMI à cette zone esac done sleep "$INTERVAL"done
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.