Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.

Cooler CPU


#!/bin/bash
# Filename: cpulimit-ghb.sh
# Version.: 09032017
# Author..: robz
# I know, I'm cheap, I should buy a better than stock cooling fan, but....
# Dynamically use the cpulimit utility to keep cpu within a sane temperature
# range when using Handbrake or another resource hammering program.
# sudo apt install cpulimit lmsensors - use PPA for the latest Handbrake.
# Dependant on the output of "sensors" you may need to tweak line ##.

if [ "$UID" != "0" ]; then                          # Get root privilege.
    sudo -k; exec gksudo --message "$(echo\
    'Enter your password please, you need root';\
    echo 'privileges to run cpulimit effectively.')"\
    "$0"
fi

max='67'                                            # Maximum temperature°C.
cores='2'                                           # Number of cpu cores.
prog='/usr/bin/ghb'                                 # Program you're limiting.
limit=$((100*cores))                                # Total 100% limit range.
base="$limit"

while [[ "$(pidof "$prog")" ]]; do
    temp=$(sensors | grep 'CPU:' | cut -c18-19)     ## Get cpu temperature.
    if [[ "$temp" -gt "$max" && "$limit" -gt '25' ]]; then
        killall /usr/bin/cpulimit                   # Kill old process.
        ((limit-=25))                               # Increment limit down.
        cpulimit -qb -P "$prog" -l "$limit"         # Start new process.
    elif [[ "$temp" -lt "$max" && "$limit" -lt "$base" ]]; then
        killall /usr/bin/cpulimit
        ((limit+=25))                               # Increment limit up.
        cpulimit -qb -P "$prog" -l "$limit"
    fi
    sleep 5
done

killall /usr/bin/cpulimit
exit


No comments: