if you want to use the least amount of pipes as possible, the following is a candidate:
Code:
<cputempcommand>sensors|sed -ne "s/Core 1: \+[-+]\([0-9]\+\).*/\1 C/p"</cputempcommand>
or you could just do the following, which will give average core temps on your system instead of 'external' cpu temps.. (meaning sensors on cpu casing or just below the cores themselves)
Code:
<cputempcommand>num=0; sum=0; for temp in $(cat /sys/devices/platform/coretemp.?/temp?_input); do num=$(($num + 1)); sum=$(($sum + $temp)); done; echo "$(($sum / $num / 1000)) C"</cputempcommand>
havent tested the latter one, do not know how popen() handles bash like syntax..
here's a shell script for all temperature readings i have on my machine, should not be hard to modify it to your own needs
Code:
#!/bin/bash
# authors:
# djurny <no(at)spam.com>
# license:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# description:
# get various temperature readings
# usage:
# $0 core
# gets average core temperature, needs coretemp installed!
# $0 gpu
# get nvidia gpu core temperature, needs nvidia-settings installed!
# $0 hdd
# gets active harddisk temperatures, needs hdparm and hddtemp installed!
# notes:
# for automated use, add NOPASSWD for hdparm, hddtemp for user to sudoers
err() {
echo "$*" 1>&2
}
get_core_temp() {
local num=0
local sum=0
for temp in $(cat /sys/devices/platform/coretemp.?/temp?_input); do
num=$(($num + 1))
sum=$(($sum + $temp))
done
if [[ $sum -eq 0 || $num -eq 0 ]]; then
err "could not get correct temperature(s) (sum='$sum' num='$num')"
return 1
fi
echo "$(($sum / $num / 1000)) C"
return 0
}
get_gpu_temp () {
local app="nvidia-settings"
if ! which $app >/dev/null 2>/dev/null; then
err "file not found '$app'"
return 1
fi
# this may need some tiddling with DISPLAY settings!
echo "$($app --terse --query GPUCoreTemp) C"
return 0
}
get_hdd_temp() {
local ret=0
local hdds="/dev/sd?"
local tmp=0
local tmpfile="/tmp/$(basename $0)"
# local app
# for app in hdparm hddtemp; do
# if ! which $app >/dev/null 2>/dev/null; then
# err "file not found '$app'"
# return 1
# fi
# done
for hdd in $hdds; do
sudo hdparm -C $hdd >$tmpfile 2>/dev/null
if [ $? -gt 0 ]; then
err "could not get powerstate for '$hdd'"
ret=1
continue
fi
if ! grep -e "active\|idle" $tmpfile >/dev/null 2>/dev/null; then
# do not allow hddtemp to spin up sleeping hdds
continue
fi
tmp=$(sudo hddtemp --numeric $hdd 2>/dev/null)
if [[ $? -gt 0 || -z "$tmp" || $tmp -eq 0 ]]; then
err "could not get hdd temp for '$hdd'"
continue
fi
echo "$tmp C"
done
return $ret
}
case "$1" in
core)
if ! get_core_temp; then
err "could not get cpu temperature"
exit 1
fi
;;
gpu)
if ! get_gpu_temp; then
err "could not get gpu temperature"
exit 1
fi
;;
hdd)
if ! get_hdd_temp; then
err "could not get hdd temperature"
exit 1
fi
;;
*)
err "do not knnow what to do for '$1'"
exit 1
;;
esac
exit 0
# EOF