bin/temps @ 46c8ae0df6cc default tip

More
author Steve Losh <steve@stevelosh.com>
date Thu, 30 Jan 2025 09:44:14 -0500
parents eb9f31c299b8
children (none)
#!/usr/bin/env bash

set -euo pipefail

function find_names {
    grep . /sys/class/hwmon/hwmon*/name
}

function find_temp_numbers {
    dir="$1"
    find "/sys/class/hwmon/$dir/" -name 'temp*_input' \
        | xargs -n1 basename \
        | tr -dc '0-9\n' \
        | sort -n
}

function display_temp {
    dir="$1"
    n="$2"

    set +e

    if test -e "/sys/class/hwmon/$dir/temp${n}_label"; then
        paste \
            <(cat "/sys/class/hwmon/$dir/temp${n}_label") \
            <(cat "/sys/class/hwmon/$dir/temp${n}_input" 2>&1)
    else
        paste \
        <(echo '???') \
        <(cat "/sys/class/hwmon/$dir/temp${n}_input")
    fi

    set -e
}

if test -z "${1:-}"; then
    find_names
else
    dir=$(find_names | grep "$1" | cut -d / -f 5)

    find_temp_numbers "$dir" | while read -r n; do
        display_temp "$dir" "$n"
    done
    # paste \
    #     <(grep . "/sys/class/hwmon/$dir/"temp*_label | sort) \
    #     <(grep . "/sys/class/hwmon/$dir/"temp*_input | sort) \
    #     | tr -s ':' ' ' \
    #     | awk '/Core/ {print $2, $3, $5/1000.0 }' \
    #     | sort -n -k2
fi