Coretemp and Byobu

Posted on 17 September 2010  •  Permalink  •  Category htpc

Being at the point to leave mbox turned on 24/7, I wanted a way to monitor it’s temperature. I installed a so called fan mate, with which I can manually adjust the CPU’s fan speed. So here’s what I did. First you need to install the Ubuntu package called lm-sensors to enable querying CPU temperature on the Zotac ION-ITX boards. Next make sure the coretemp module is loaded, either modprobe‘ing it manually or by adding it to /etc/modules to have it load automatically.

After doing that, type sensors to see the temperature of the CPU(s). Now that’s nice, but wouldn’t it be even much cooler to add a temperature display to byobu? That’s what I’d think. So create a file 5_sensors in ~/.byobu/bin, make it executable and fire up your favorite editor to add the following content to it:

#!/bin/bash

t=`sensors | grep "Core 0:" \
  | sed -e 's/Core 0: \++//' \
  | sed -s 's/\.0°C \+(crit.*).*$//'`

if [ $t -gt 49 ]; then
  color="kR"
else
  color="kB"
fi

printf "\005{= %s}%s\005{-}\005{= kw}\260%s\005{-}" "$color" "$t" "C"

There you go, fire up byobu and you’ll see a new field appear (make sure to enable the “custom” status notifications, by pressing F9 for the byobu menu, go into “Toggle status notifications” and check “custom”). I use color red for a temperature above 49 degrees, which is encoded in the if statement. Feel free to change it however you like!