neil in gemini space
cpu temp revisited - 2021-05-29
my first attempt at a cpu temp script was not giving me now data but average since boot data: not what i intended!
so i revisited cputemp.sh:
#!/bin/bash
#
# echoes datetime, cpu Tdie, and approximate cpu load
# use as is or as a cronjob (example: change the path and log file as you need to):
# */2 * * * * /home/a_user/cputemp.sh >> cputemp.log
#
# n c timms
# 2021-05-29
# echo date time in UTC
# echo sensors output
# grep on Tdie to get CPU overall temp and
# awk to only print the temperature source Tdie and the cpu temerature
# iostat -y omit first report with stats since boot;
# -c 1 1 report cpu utilisation since 1 second 1 once
# and in case we wonder -c 1 1 does not deliver what this
# this script wants so -yc 1 1 it is!
# tail and head to isolate the line of data
# awk adds up the first three columns user, nice, system,
# and adds the word load for context.
#
# this script will take at least one second to complete because of
# the iostat interval of 1 second
#
# bash scripting is like lego for pedants!
# that's all folks
echo -n $(date -u +%FT%TZ); \
echo -n " $(sensors k10temp-pci-00c3 | \
grep Tdie | awk '{ print $1" "$2 }')"; \
iostat -yc 1 1 | tail -n4 | head -n1 | \
awk '{ print " "$1+$2+$3"% load" }'
the head and tail changed to deal with the iostat output when using options -yc.
---
---
neil.gemini@mingmengtou.org
content licensed CC-BY-SA 4.0 unless stated.