#!/bin/bash #nvautoadjust #periodically checks Nvidia GPU temperature and adjusts fan appropriately #recommended invokation: nvautoadjust & #run at startup to continually monitor temperature and adjust fan speed. #sets the refresh interval in seconds interval=5 #sets the threshold temperatures and fan speeds for the three levels of cooling #threshold is in degrees c, speed is in percentage of maximum. Set a number between #35 and 100 for fan speeds. min_threshold=45 max_threshold=60 min_speed=50 mid_speed=70 max_speed=100 # continually loop while [ "1" -eq "1" ]; do #get current temperature and fan speed current_temp=`nvidia-smi -q -d TEMPERATURE | grep 'GPU Current' | sed 's/.*\([0-9]\{2\}\).*/\1/'` current_speed=`nvidia-smi -q | grep Fan | sed 's/.* \(1\?[0-9]\{2\}\) .*/\1/'` #check current temperature and adjust fan speed #only set the speed if it actually needs changing, as nvidia-settings eats CPU cycles if [[ $current_temp > $min_threshold ]]; then if [[ $current_temp > $max_threshold ]]; then #if temp greater than 60, set fan speed to max if [[ $current_speed != $max_speed ]]; then nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed="$max_speed" > /dev/null fi fi #if temp greater than 45, set fan speed to mid if [[ $current_speed != $mid_speed ]]; then nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed="$mid_speed" > /dev/null fi else #if temp below 45, set fan speed to minimum if [[ $current_speed != $min_speed ]]; then echo set nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed="$min_speed" > /dev/null fi fi #wait until interval expires before rechecking sleep "$interval" done