Skip to content

Instantly share code, notes, and snippets.

@MicroCBer
Created January 27, 2024 12:21
Show Gist options
  • Save MicroCBer/a46eab57568b16798119a49f01cabd53 to your computer and use it in GitHub Desktop.
Save MicroCBer/a46eab57568b16798119a49f01cabd53 to your computer and use it in GitHub Desktop.
Basic fan control script for P40
#!/bin/bash
# Check if running with sudo
if [ "$EUID" -ne 0 ]; then
echo "Please run with sudo:"
echo "sudo $0"
exit
fi
# Enable PWM
echo 1 > /sys/class/hwmon/hwmon2/pwm2_enable
while true; do
# Get GPU temperature
temp=$(nvidia-smi -q -d TEMPERATURE | awk '/GPU Current Temp/ {print $5}')
# Calculate speed based on temperature
speed=$(awk -v temp="$temp" 'BEGIN{ speed = int(-1/(temp - 100)*2300 - 25); if(speed < 0) speed = 0; if(speed > 254) speed = 254; print speed }')
# Write speed to hwmon file
echo "$speed" > /sys/class/hwmon/hwmon2/pwm2
# Log the temperature and speed
echo "Temperature: $temp C -- Speed: $speed"
# Wait for 5 seconds before the next iteration
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment