[cron] Autorun shell to Curve Control Linux GPU fans

environment

Linux Ubuntu bionic xfce

Introduction

I managed to find a solution by hunting the Web to control the curve of Nvidia's grabbo (controlling the fan according to the temperature of the grabbo) on Linux.

procedure

  1. Prepare a shell for fan control (https://github.com/FedoraTipper/Nvidia-Fan-Curve-Linux)
  2. Make crontab run automatically at startup

1. Fan-controlled shell

/path/to/script


#!/bin/bash
#Make sure to enable nvidia-xconfig --cool-bits=4


#This new script works with version 378.13 driver
#Old script is not functional (on Arch, at least)
#Changed up some options and flags for nvidia-settings
#Added some comments for clarity, in case other people want to make improved forks

#enable headless mode 
#request lightdm installed - apt install --no-install-recommends xorg lightdm for debian/ubuntu
headless=true
verbose=false

if [ "$headless" = true ] ; then
    export DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0
fi

#Enable user defined fancontrol for all gpu
nvidia-settings -a "GPUFanControlState=1"

while true
do

    #gpu index
    i=0

    #Get GPU temperature of all cards
    for gputemp in $(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader);do
    
    if [ "$verbose" = true ] ; then
        echo "gpu ${i} temp ${gputemp}"; 
    fi

        #Note: you need to set the minimum fan speed to a non-zero value, or it won't work
        #This fan profile is being used in my GTX580 (Fermi). Change it as necessary

        #If temperature is between X to Y degrees, set fanspeed to Z value
        case "${gputemp}" in
                0[0-9])
                        newfanspeed="10"
                        ;;
                1[0-9])
                        newfanspeed="15"
                        ;;
                2[0-9])
                        newfanspeed="20"
                        ;;
                3[0-9])
                        newfanspeed="20"
                        ;;
                4[0-9])
                        newfanspeed="30"
                        ;;
                5[0-4])
                        newfanspeed="35"
                        ;;
                5[5-6])
                        newfanspeed="40"
                        ;;
                5[7-9])
                        newfanspeed="50"
                        ;;
                6[0-5])
                        newfanspeed="60"
                        ;;
                6[6-9])
                        newfanspeed="65"
                        ;;
                7[0-5])
                        newfanspeed="70"
                        ;;
                7[6-9])
                        newfanspeed="85"
                        ;;
                *)
                        newfanspeed="100"
                        ;;
        esac
        
        nvidia-settings -a "[fan-${i}]/GPUTargetFanSpeed=${newfanspeed}" 2>&1 >/dev/null
        
        if [ "$verbose" = true ] ; then
            echo "gpu ${i} new fanspeed ${newfanspeed}"; 
        fi
        
        sleep 1s
    #increment gpu index
    i=$(($i+1))
    done
done

2. crontab settings

Setting

Add in the editor

Start editor


crontab -e

/tmp/crontab.xxxxx


@reboot /path/to/script

Added with one liner

echo '@reboot /path/to/script' | crontab

Check the settings

crontab -l

result


@reboot /path/to/script

Recommended Posts

[cron] Autorun shell to Curve Control Linux GPU fans
[Linux ☓ Nvidia] Curve Control the fan