52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Path to the temperature sensor and PWM control
|
|
TEMP_SENSOR="/sys/class/hwmon/hwmon1/temp1_input"
|
|
PWM_CONTROL="/sys/class/hwmon/hwmon2/pwm1" # Adjust this path as needed
|
|
|
|
# Function to set fan speed using PWM control
|
|
set_fan_speed() {
|
|
local speed=$1
|
|
echo $speed | sudo tee $PWM_CONTROL
|
|
}
|
|
|
|
# Wait for the hwmon files to be available
|
|
while [ ! -f "$TEMP_SENSOR" ] || [ ! -f "$PWM_CONTROL" ]; do
|
|
echo "Waiting for hwmon files..."
|
|
sleep 1
|
|
done
|
|
|
|
echo "hwmon files found. Starting fan control."
|
|
|
|
# Main loop
|
|
while true; do
|
|
# Read the current temperature
|
|
temp=$(cat $TEMP_SENSOR)
|
|
temp=$((temp / 1000)) # Convert to degrees Celsius
|
|
|
|
# Print the current temperature
|
|
echo "Current temperature: $temp°C"
|
|
|
|
# Adjust fan speed based on temperature
|
|
if [ $temp -lt 50 ]; then
|
|
set_fan_speed 25 # Approximately 25% speed
|
|
elif [ $temp -lt 60 ]; then
|
|
set_fan_speed 45 # Approximately 50% speed
|
|
elif [ $temp -lt 65 ]; then
|
|
set_fan_speed 60 # Approximately 75% speed
|
|
elif [ $temp -lt 75 ]; then
|
|
set_fan_speed 120 # High speed
|
|
else
|
|
set_fan_speed 255 # Maximum speed
|
|
fi
|
|
|
|
# Check for critical temperature
|
|
if [ $temp -ge 85 ]; then
|
|
echo "Critical temperature reached: $temp°C" | sudo tee /dev/kmsg
|
|
set_fan_speed 255 # Ensure fan is at maximum speed
|
|
fi
|
|
|
|
# Sleep for a while before checking again
|
|
sleep 10
|
|
done
|