#!/bin/bash check_start_time() { local start_time="$1" local current_time=$(date +%s) local time_diff=$((current_time - start_time)) if [ $time_diff -ge 60 ]; then echo 0 else echo 1 fi } check_temperature() { temp_lines=$(ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" sdr type temperature 2>/dev/null | grep -e degrees | awk '{print $(NF-2)}') temp_arr="" readarray -t temp_arr <<< "$temp_lines" sorted_temps=($(printf "%s\n" "${temp_arr[@]}" | sort -nr)) max_temp=${sorted_temps[0]} if [ "$max_temp" -le 60 ] && [ "$CURRENT_PROFILE" != "MANUAL" ]; then # enable manual fan control ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" raw 0x30 0x30 0x01 0x00 &> /dev/null # set initial fan to 20% ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" raw 0x30 0x30 0x02 0xff 0x14 &> /dev/null CURRENT_PROFILE="MANUAL" elif [ "$max_temp" -gt 60 ] && [ "$CURRENT_PROFILE" != "AUTO" ]; then # enable Dell fan control ipmitool -I lanplus -H "$HOST" -U "$USER" -P "$PASS" raw 0x30 0x30 0x01 0x01 &> /dev/null CURRENT_PROFILE="AUTO" fi } disable_third_party_mode (){ # disable 3rd party pcie fan mode output=$(sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$USER@$HOST" "racadm get system.pcieslotlfm" 2>/dev/null) pcie_ports_count=$(echo "$output" | grep -c 'System.pcieslotlfm') # Iterate through each PCIe port and disable third party mode for ((i=1; i<=pcie_ports_count; i++)); do sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$USER@$HOST" "racadm set system.pcieslotlfm.$i.lfmmode disabled" &> /dev/null done } HOST="" USER="" PASS="" VMID="" CURRENT_PROFILE="" start_time=$(ps -o lstart= -p $(cat /var/run/qemu-server/$VMID.pid)) start_time=$(date -d "$start_time" +%s) while [[ $(check_start_time "$start_time") -eq 1 ]] do sleep 5 done disable_third_party_mode while true; do check_temperature if [[ "$CURRENT_PROFILE" == "AUTO" ]]; then sleep 300 else sleep 60 fi done