Last active
November 15, 2024 12:58
-
-
Save dataslayermedia/fb20aae9dea64bca286b5e6d189027b8 to your computer and use it in GitHub Desktop.
real-time-temperature-output-coral-ai-pcie-accelerators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to convert millidegree Celsius to Fahrenheit | |
convert_to_fahrenheit() { | |
local temp_milli_c=$1 | |
# Convert millidegree Celsius to Celsius | |
local temp_c=$(echo "scale=4; $temp_milli_c / 1000" | bc) | |
# Convert Celsius to Fahrenheit | |
echo "scale=2; ($temp_c * 9 / 5) + 32" | bc | |
} | |
# Main loop to continuously monitor the temperature | |
while true; do | |
clear | |
echo "Monitoring Coral PCIe Accelerators Temperature in Fahrenheit" | |
# Dynamically find all apex devices and read their temperatures | |
for device_path in /sys/class/apex/apex_*; do | |
if [ -f "$device_path/temp" ]; then | |
device_name=$(basename "$device_path") | |
temp_milli_c=$(cat "$device_path/temp") | |
temp_f=$(convert_to_fahrenheit $temp_milli_c) | |
echo "$device_name: $temp_f°F" | |
else | |
echo "$device_name: Temperature readout not available" | |
fi | |
done | |
# Wait for a second before the next update | |
sleep 1 | |
done |
In Celsius if anyone needs and don't know how to do:
#!/bin/bash
# Function to convert millidegree Celsius to Celsius
convert_to_c() {
local temp_milli_c=$1
# Convert millidegree Celsius to Celsius
local temp=$temp_milli_c/1000
echo "scale=2; $temp" | bc
}
# Main loop to continuously monitor the temperature
while true; do
clear
echo "Monitoring Coral PCIe Accelerators Temperature in Celsius"
# Dynamically find all apex devices and read their temperatures
for device_path in /sys/class/apex/apex_*; do
if [ -f "$device_path/temp" ]; then
device_name=$(basename "$device_path")
temp_milli_c=$(cat "$device_path/temp")
temp_c=$(convert_to_c $temp_milli_c)
echo "$device_name: $temp_c°C"
else
echo "$device_name: Temperature readout not available"
fi
done
# Wait for a second before the next update
sleep 1
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script prints out the temperature of all PCIe accelerators in fahrenheit