Created
October 14, 2017 07:34
-
-
Save patrickjennings/ceabd8e9248d0c44fb3b577b5b513995 to your computer and use it in GitHub Desktop.
Bash script to control the fan of an NVIDIA GPU.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Requirements: | |
# Coolbits bit 2 to enable fan control. | |
# Dependencies: | |
# GNU BC: https://www.gnu.org/software/bc/ | |
sleep_time="5s" | |
# On close, set fan speed back to automatic mode. | |
trap 'nvidia-settings -a "GPUFanControlState=0"; exit 0;' SIGINT SIGTERM | |
# Set fan speed to manual mode. | |
nvidia-settings -a "GPUFanControlState=1" 1> /dev/null | |
# Set the fan speed based on GPU temp, in celsius, as the argument. | |
set_fan_speed() { | |
case "${1}" in | |
[0-8][0-9]) # 0-89 | |
fan_speed=$(printf %.0f $(echo "1.62 + e(0.0515*$1)" | bc -l)) | |
;; | |
*) # Default | |
fan_speed="100" | |
;; | |
esac | |
nvidia-settings -a "GPUTargetFanSpeed=${fan_speed}" 2>&1 >/dev/null | |
echo "Setting Nvidia fan speed: $fan_speed Temp: $1" | |
} | |
while true | |
do | |
gputemp=$(nvidia-settings -q GPUCoreTemp | awk -F ":" 'NR==2{print $3}' | sed 's/[^0-9]*//g') | |
if [ "$gputemp" != "$oldtemp" ] ; then | |
set_fan_speed "$gputemp" | |
fi | |
oldtemp=$gputemp | |
sleep "$sleep_time" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment