Created
November 5, 2013 13:02
-
-
Save MihailJP/7318694 to your computer and use it in GitHub Desktop.
Script to control the fan speed automatically (works only for NVIDIA graphic cards)
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 | |
# Script to control the fan speed automatically | |
setFanSpeed() { | |
eval "nvidia-settings -a GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$1 > /dev/null" | |
} | |
cleanup() { | |
eval "nvidia-settings -a GPUFanControlState=0" | |
exit | |
} | |
declare -i gpuTemp | |
# Set cleanup function (clean up and exit when interrupted) | |
trap cleanup 1 2 3 15 20 | |
while : # Loop | |
do | |
# Get NVIDIA GPU temperature | |
gpuTemp=$(nvidia-settings -q gpucoretemp | grep '^ Attribute' | \ | |
head -n 1 | perl -pe 's/^.*?(\d+)\.\s*$/\1/;') | |
echo -en "Current GPU temperature: $gpuTemp \r" | |
# Set GPU fan speed | |
if [ $gpuTemp -ge 70 ]; then | |
setFanSpeed 100 | |
elif [ $gpuTemp -ge 65 ]; then | |
setFanSpeed 90 | |
elif [ $gpuTemp -ge 60 ]; then | |
setFanSpeed 75 | |
elif [ $gpuTemp -ge 55 ]; then | |
setFanSpeed 60 | |
elif [ $gpuTemp -ge 50 ]; then | |
setFanSpeed 50 | |
else | |
setFanSpeed 40 | |
fi | |
# Interval | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple and Great Script. Thanks @MihailJP!
Attaching variation of this for 5 gpus and with X env-vars so can be run from command-line with X running in the background.