From 6c1f613ddb256e392e6cd492c17d3a9fe9a8c8a5 Mon Sep 17 00:00:00 2001 From: Ryan Bush <20880666+rpbush@users.noreply.github.com> Date: Fri, 13 Jan 2023 11:45:49 +0100 Subject: [PATCH 1/4] Added comments for clarity. --- Dell_iDRAC_fan_controller.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index 0bab993..40a2ef9 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -1,12 +1,19 @@ +Sure, here is an improved version of the script with added comments: + +Copy code #!/bin/bash # Define global functions +# This function applies Dell's default dynamic fan control profile apply_Dell_profile () { + # Use ipmitool to send the raw command to set fan control to Dell default ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01 > /dev/null CURRENT_FAN_CONTROL_PROFILE="Dell default dynamic fan control profile" } +# This function applies a user-specified static fan control profile apply_user_profile () { + # Use ipmitool to send the raw command to set fan control to user-specified value ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x00 > /dev/null ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED > /dev/null CURRENT_FAN_CONTROL_PROFILE="User static fan control profile ($DECIMAL_FAN_SPEED%)" @@ -19,12 +26,12 @@ gracefull_exit () { exit 0 } +# Trap the signals for container exit and run gracefull_exit function trap 'gracefull_exit' SIGQUIT SIGKILL SIGTERM # Prepare, format and define initial variables -#readonly DELL_FRESH_AIR_COMPLIANCE=45 - +# Check if FAN_SPEED variable is in hexadecimal format, if not convert it to hexadecimal if [[ $FAN_SPEED == 0x* ]] then DECIMAL_FAN_SPEED=$(printf '%d' $FAN_SPEED) @@ -36,6 +43,8 @@ fi # Log main informations given to the container echo "Idrac/IPMI host: $IDRAC_HOST" + +# Check if the Idrac host is set to 'local', and set the LOGIN_STRING accordingly if [[ $IDRAC_HOST == "local" ]] then LOGIN_STRING='open' @@ -44,11 +53,14 @@ else echo "Idrac/IPMI password: $IDRAC_PASSWORD" LOGIN_STRING="lanplus -H $IDRAC_HOST -U $IDRAC_USERNAME -P $IDRAC_PASSWORD" fi + +# Log the fan speed objective, CPU temperature threshold, and check interval echo "Fan speed objective: $DECIMAL_FAN_SPEED%" echo "CPU temperature treshold: $CPU_TEMPERATURE_TRESHOLD°C" echo "Check interval: ${CHECK_INTERVAL}s" echo "" +# Define the interval for printing readonly TABLE_HEADER_PRINT_INTERVAL=10 i=$TABLE_HEADER_PRINT_INTERVAL IS_DELL_PROFILE_APPLIED=true From 9411c52cde16f8dc80d1e9f8a0bc9a53f4c0571a Mon Sep 17 00:00:00 2001 From: Ryan Bush <20880666+rpbush@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:15:43 +0100 Subject: [PATCH 2/4] Updated comments --- Dell_iDRAC_fan_controller.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index 40a2ef9..fbae5c6 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -67,9 +67,11 @@ IS_DELL_PROFILE_APPLIED=true # Start monitoring while true; do + # Sleep for the specified interval before taking another reading sleep $CHECK_INTERVAL & SLEEP_PROCESS_PID=$! + # Retrieve sensor data using ipmitool DATA=$(ipmitool -I $LOGIN_STRING sdr type temperature | grep degrees) INLET_TEMPERATURE=$(echo "$DATA" | grep Inlet | grep -Po '\d{2}' | tail -1) EXHAUST_TEMPERATURE=$(echo "$DATA" | grep Exhaust | grep -Po '\d{2}' | tail -1) @@ -77,10 +79,13 @@ while true; do CPU1_TEMPERATURE=$(echo $CPU_DATA | awk '{print $1;}') CPU2_TEMPERATURE=$(echo $CPU_DATA | awk '{print $2;}') + # Define functions to check if CPU1 and CPU2 temperatures are above the threshold CPU1_OVERHEAT () { [ $CPU1_TEMPERATURE -gt $CPU_TEMPERATURE_TRESHOLD ]; } CPU2_OVERHEAT () { [ $CPU2_TEMPERATURE -gt $CPU_TEMPERATURE_TRESHOLD ]; } + # Initialize a variable to store comments COMMENT=" -" + # Check if CPU1 is overheating and apply Dell profile if true if CPU1_OVERHEAT then apply_Dell_profile From 01934c1155685ba6afdab82831e4b31c7bd4fd36 Mon Sep 17 00:00:00 2001 From: Ryan Bush <20880666+rpbush@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:16:17 +0100 Subject: [PATCH 3/4] Update Dell_iDRAC_fan_controller.sh --- Dell_iDRAC_fan_controller.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index fbae5c6..f68edf2 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -1,6 +1,3 @@ -Sure, here is an improved version of the script with added comments: - -Copy code #!/bin/bash # Define global functions From 7709206447a4fe8b091f1a8ac8b1dbc07ae83d05 Mon Sep 17 00:00:00 2001 From: Ryan Bush <20880666+rpbush@users.noreply.github.com> Date: Sat, 14 Jan 2023 03:55:08 +0100 Subject: [PATCH 4/4] Added more comments --- Dell_iDRAC_fan_controller.sh | 53 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index f68edf2..ce5e154 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -86,46 +86,45 @@ while true; do if CPU1_OVERHEAT then apply_Dell_profile - + # Set the flag to indicate that Dell profile is applied if ! $IS_DELL_PROFILE_APPLIED then IS_DELL_PROFILE_APPLIED=true - - if CPU2_OVERHEAT - then - COMMENT="CPU 1 and CPU 2 temperatures are too high. Dell default dynamic fan control profile applied." - else - COMMENT="CPU 1 temperature is too high. Dell default dynamic fan control profile applied." - fi fi - elif CPU2_OVERHEAT - then - apply_Dell_profile - if ! $IS_DELL_PROFILE_APPLIED + if CPU2_OVERHEAT then - IS_DELL_PROFILE_APPLIED=true - COMMENT="CPU 2 temperature is too high. Dell default dynamic fan control profile applied." + COMMENT="CPU 1 and CPU 2 temperatures are too high, Dell default dynamic fan control profile applied for safety" + else + COMMENT="CPU 1 temperature is too high, Dell default dynamic fan control profile applied for safety" fi else - apply_user_profile - - if $IS_DELL_PROFILE_APPLIED + # Check if CPU2 is overheating and apply Dell profile if true + if CPU2_OVERHEAT then - COMMENT="CPU temperature decreased and is now OK (<= $CPU_TEMPERATURE_TRESHOLD°C). User's fan control profile applied." - IS_DELL_PROFILE_APPLIED=false + apply_Dell_profile + if ! $IS_DELL_PROFILE_APPLIED + then + IS_DELL_PROFILE_APPLIED=true + fi + COMMENT="CPU 2 temperature is too high, Dell default dynamic fan control profile applied for safety" + else + # Check if user profile is applied and apply it if not + if $IS_DELL_PROFILE_APPLIED + then + apply_user_profile + IS_DELL_PROFILE_APPLIED=false + fi fi fi - - # Print temperatures array - if [ $i -ge $TABLE_HEADER_PRINT_INTERVAL ] + # Print the results, including the current fan control profile and comment + if [ $i -eq $TABLE_HEADER_PRINT_INTERVAL ] then - echo " ------- Temperatures -------" - echo " Date & time Inlet CPU 1 CPU 2 Exhaust Active fan speed profile Comment" + echo "Time CPU1 CPU2 Inlet Exhaust Fan Control Profile Comment" i=0 fi - printf "%12s %3d°C %3d°C %3d°C %5d°C %40s %s\n" "$(date +"%d-%m-%y %H:%M:%S")" $INLET_TEMPERATURE $CPU1_TEMPERATURE $CPU2_TEMPERATURE $EXHAUST_TEMPERATURE "$CURRENT_FAN_CONTROL_PROFILE" "$COMMENT" - - ((i++)) + echo "$(date +%T) $CPU1_TEMPERATURE°C $CPU2_TEMPERATURE°C $INLET_TEMPERATURE°C $EXHAUST_TEMPERATURE°C $CURRENT_FAN_CONTROL_PROFILE $COMMENT" + i=$(($i+1)) wait $SLEEP_PROCESS_PID done +