Message boards : Questions and problems : Linux BOINC temperature script
Message board moderation
Author | Message |
---|---|
![]() ![]() Send message Joined: 13 May 10 Posts: 40 ![]() |
Hi all, I wrote a simple bash script to change the CPU usage according to its temperature. I wrote this for my AMD Athlon 64 X2 (R) [2006] on Debian Wheezy (should also work on Ubuntu ...?). You'll need the packages lm-sensors and sed. Note that you have to start this as root or with sudo rights (to change the BOINC owned preferences file). Suggestions and changes are welcome. I will update this post. Use your favorite internet search enginge for your CPU's suggested temperature and set TARGTEMP. #!/bin/bash #Script to adapt BOINC's global CPU usage to CPU temperature #Use your favorite internet search enginge #for your CPU's suggested temperature #Written for AMD Athlon 64 X2 (R) [2006] # #Released into the Public Domain or CC0, your choice. #Thanks to grymoire.com, tldp.org, stackoverflow.com #and all of the Open Source Community. #Set target temperature of your CPU in Degree Celsius here: TARGTEMP=50 #Set how often usage is changed and changes are put on screen in minutes CHANGEPAUSE=1 OUTPUTPAUSE=15 #Simple check for dependencies DEPENDENCIES="sensors sed" for i in $DEPENDENCIES; do if ! command -v "$i" >/dev/null then echo "Please check if you have the package necessary for \033[1m$i\033[0m installed." && exit 1; fi; done #Change to BOINC_DIR and create temporary folder for backup BOINCDAT=$(grep BOINC_DIR /etc/default/boinc-client | grep -v "\#" | cut -d"\"" -f2) cd $BOINCDAT mkdir -p tmp while [ -e "lockfile" ]; do #Grab current CPU usage settings CURRCPU=$(grep "<cpu_usage_limit>" global_prefs_override.xml | cut -d">" -f2 | cut -d"." -f1) #Grab current temperature CURRTEMP=$(sensors | grep "Core1 Temp" | head -1 | cut -d"+" -f2 | cut -d"." -f1) #In-/Decrease usage by two percent if [ "$CURRTEMP" -gt "$TARGTEMP" ]; then ADVCPU=$(( $CURRCPU-2 )); else ADVCPU=$(( $CURRCPU+2 )); fi #Calculates pause for output on screen and also to log: REMAINDER=$(( $(date +"%-M") % $OUTPUTPAUSE )) if [ "$REMAINDER" = 0 ]; then echo $(date +"%F %H:%M") Advised CPU is "$ADVCPU" %.\ | tee -a boinctemp.log fi #Stream EDit line with cpu_usage_limit by substituting CURRCPU with ADVCPU sed '/cpu_usage_limit/ s/'$CURRCPU'/'$ADVCPU'/' <global_prefs_override.xml >tmp/global_prefs_override.xml #Check temporary backup and copy to original (errors go to output AND into boinctemp.log) if grep "<cpu_usage_limit>"$ADVCPU"" tmp/global_prefs_override.xml 2>&1>/dev/null | tee -a boinctemp.log; then cp tmp/global_prefs_override.xml global_prefs_override.xml else echo "Can't edit preferences file. Check your disk." fi boinccmd --read_global_prefs_override #fi sleep "$CHANGEPAUSE"m done Apologies to other flavour users but this should be easily adaptable. My reasons to participate in grid computing: 1. I'm using true renewable energy (German accreditation; no certificate purchasing) 2. Production and disposal (will) amount to about 95% of the energy "used" during the lifetime of my PC 3. Helping |
Copyright © 2025 University of California.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software Foundation.