NVidia Fan Speed Revisited
One of the comments to my last post about adjusting the fan speed on your NVidia graphics card was that what was needed was a script to adjust the speed based on the temperature. The script presented here does just that.
The script takes a single argument, the desired temperature (default is 50C). It then calculates a low and high temperature based on this and increases the fan speed if the temperature gets above the max or decreases it if the temperature gets below the minimum.
It determines the temperature and fan speed by parsing the output of the nvclock command. Without further ado, here is the script:
#!/bin/bash
#
# Adjust fan speed automatically.
# Location of the nvclock program.
nvclock_bin=/usr/local/bin/nvclock
# Target temperature for video card.
target_temp=50
# Value used to calculate the temperature range (+/- target_temp).
target_range=1
# Time to wait before re-checking.
sleep_time=120
# Minimum fan speed.
min_fanspeed=20
# Fan speed increment.
adj_fanspeed=5
if [[ "$1" ]]; then target_temp=$1; fi
let target_temp_low=target_temp-target_range
let target_temp_high=target_temp+target_range
while true
do
temp=$(echo $($nvclock_bin --info | grep -i 'GPU temperature' | cut -d ':' -f 2))
pwm=$(echo $($nvclock_bin --info | grep -i 'PWM duty cycle' | cut -d ':' -f 2))
temp_val=${temp/C/}
pwm_val=${pwm%.*}
if [[ $temp_val -gt $target_temp_high ]]; then
# Temperature above target, see if the fan has any more juice.
if [[ $pwm_val -lt 100 ]]; then
echo "Increasing GPU fan speed, temperature: $temp"
let pwm_val+=adj_fanspeed
if [[ $pwm_val -gt 100 ]]; then pwm_val=100; fi
$nvclock_bin -f --fanspeed $pwm_val
fi
elif [[ $temp_val -lt $target_temp_low ]]; then
# Temperature below target, lower the fan speed
# if we're not already at the minimum.
if [[ $pwm_val -gt $min_fanspeed ]]; then
echo "Decreasing GPU fan speed, temperature: $temp"
let pwm_val-=adj_fanspeed
if [[ $pwm_val -lt $min_fanspeed ]]; then pwm_val=$min_fanspeed; fi
$nvclock_bin -f --fanspeed $pwm_val
fi
fi
sleep $sleep_time
done
# vim: tabstop=4: shiftwidth=4: noexpandtab:
# kate: tab-width 4; indent-width 4; replace-tabs false;
The values set at the top of the script can be changed to adjust:
- Where nvclock is located.
- The default target temperature.
- How wide the temperature range is.
- How often the temperature is checked.
- What the minimum fan speed is.
- How much the fan speed is adjusted when it's changed.
Mitch Frazier is an Associate Editor for Linux Journal.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Using Salt Stack and Vagrant for Drupal Development
- Reply to comment | Linux Journal
2 hours 56 min ago - Dynamic DNS
3 hours 30 min ago - Reply to comment | Linux Journal
4 hours 29 min ago - Reply to comment | Linux Journal
5 hours 19 min ago - Not free anymore
9 hours 21 min ago - Great
13 hours 8 min ago - Reply to comment | Linux Journal
13 hours 16 min ago - Understanding the Linux Kernel
15 hours 31 min ago - General
18 hours 59 sec ago - Kernel Problem
1 day 4 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Update script
#!/bin/bash # # Adjust fan speed automatically. # Ver. DarkPhoinix # Location of the nvclock program. nvclock_bin=/usr/bin/nvclock # Target temperature for video card. target_temp=50 # Value used to calculate the temperature range (+/- target_temp). target_range=5 # Time to wait before re-checking. sleep_time=5 # Minimum fan speed. min_fanspeed=20 # Fan speed increment. adj_fanspeed=1 if [[ "$1" ]]; then target_temp=$1; fi let target_temp_low=target_temp-target_range let target_temp_high=target_temp+target_range while true do temp=$(echo $($nvclock_bin --info | grep -i 'GPU temperature' | cut -d ':' -f 2)) pwm=$(echo $($nvclock_bin --info | grep -i 'Fanspeed' | cut -d ':' -f 2)) temp_val=${temp/C/} pwm_val=${pwm%.*} if [[ $temp_val -gt $target_temp_high ]]; then # Temperature above target, see if the fan has any more juice. if [[ $pwm_val -lt 100 ]]; then echo "Increasing GPU fan speed, temperature: $temp" let pwm_val+=adj_fanspeed if [[ $pwm_val -gt 100 ]]; then pwm_val=100; fi $nvclock_bin -f --fanspeed $pwm_val fi elif [[ $temp_val -lt $target_temp_low ]]; then # Temperature below target, lower the fan speed # if we're not already at the minimum. if [[ $pwm_val -gt $min_fanspeed ]]; then echo "Decreasing GPU fan speed, temperature: $temp" let pwm_val-=adj_fanspeed if [[ $pwm_val -lt $min_fanspeed ]]; then pwm_val=$min_fanspeed; fi $nvclock_bin -f --fanspeed $pwm_val fi fi sleep $sleep_time done # vim: tabstop=4: shiftwidth=4: noexpandtab: # kate: tab-width 4; indent-width 4; replace-tabs false;Something in /etc/init.d
I inserted it a line to execute it into /etc/init.d/boot.local, but that's on openSuSE so it may have to go somewhere else in your case depending on what distro you use.
And actually I just inserted a line to run nvclock and set the speed to 40% on boot:
... # /etc/init.d/boot.local ... nvclock_bin=/home/mitch/bindirs/nvclock/bin/nvclock nvclock_speed=40 if [[ -x $nvclock_bin ]]; then $nvclock_bin -f -F $nvclock_speed fiMitch Frazier is an Associate Editor for Linux Journal.
how do i run this script?
What program package do i need to insert this into to run this script?