48 lines
753 B
Bash
Executable File
48 lines
753 B
Bash
Executable File
#!/bin/bash
|
|
START=$(date +%s)
|
|
|
|
usage() {
|
|
local name=${0##*/}
|
|
|
|
cat <<-EOF
|
|
Usage: ${name} [-h || --help]
|
|
|
|
measures the cpu's core temperature and writes it with a timestamp to stdout.
|
|
EOF
|
|
}
|
|
|
|
#format the temperature to float value
|
|
format_temp() {
|
|
ftemp=${1:0:2}
|
|
|
|
ftemp+="."
|
|
ftemp+=${1:2:1}
|
|
|
|
echo "${ftemp}"
|
|
}
|
|
|
|
ZONE=/sys/class/thermal/thermal_zone0/temp
|
|
|
|
#retrieve the cpu's temperature from /sys/class/thermal/thermal_zone0/temp
|
|
measure_temp() {
|
|
cpu_temp=$(cat ${ZONE})
|
|
|
|
formatted_temp=$(format_temp "${cpu_temp}")
|
|
|
|
echo "${formatted_temp}"
|
|
}
|
|
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
usage
|
|
exit 0
|
|
fi
|
|
|
|
while true; do
|
|
NOW=$(date +%s)
|
|
TS=$((NOW - START))
|
|
TEMP=$(measure_temp)
|
|
echo "${TS} ${TEMP}"
|
|
sleep 1
|
|
done
|
|
|