Created
December 29, 2011 15:31
-
-
Save AlD/1534582 to your computer and use it in GitHub Desktop.
;-)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# target temperature | |
ttemp=22 | |
# heating slope | |
slope=5 | |
############################################ | |
debug= | |
cores=$(grep -c ^processor$'\t': /proc/cpuinfo); : ${cores:=1} | |
heat () { | |
ctemp=$(sensors | sed -nre 's/^[^°]*[+-]([0-9]+)\.[0-9]°.*/\1/p;' | sort -n | head -n 1) | |
tdiff=$(( $ttemp - $ctemp )) | |
echo -n "${ctemp}°C/${ttemp}°C"$'\r' | |
[[ "$debug" ]] && echo | |
[[ "$debug" ]] && echo Current temperature ${ctemp}°C, target temperature ${ttemp}°C, temperature delta is ${tdiff}°C | |
if [[ ! "$tdiff" -gt 0 ]]; then | |
[[ "$debug" ]] && echo no need to heat | |
return 0 | |
fi | |
for ((i=0; i<$cores; i++)) { | |
[[ "$debug" ]] && echo "Spawning cpu hog #$((i+1))/$cores" | |
while :; do :; done & | |
} | |
dur=$(( tdiff * slope )) | |
if [[ "$dur" -gt "$ttemp" ]]; then | |
dur=$ttemp | |
fi | |
[[ "$debug" ]] && echo heating for $dur seconds... | |
sleep $dur | |
while read line; do | |
[[ "$debug" ]] && echo killing... | |
kill %$(( ++job )) | |
done < <(jobs -p) | |
} | |
while sleep $ttemp; do | |
heat & | |
done | |
# licensed under GPL, Daniel Albers <[email protected]>, 20111229 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment