Skip to content

Commit

Permalink
iiitl#8 CPU die temperature in Celsius and Fahrenheit
Browse files Browse the repository at this point in the history
Bash Script to get the cpu temperature in milli celsius and then  convert it to celsius and fahrenheit
  • Loading branch information
M-ayank2005 committed Mar 16, 2024
1 parent d18e2cf commit 0459793
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/cpu-temperature
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#!/usr/bin/env bash

grep -E 'Tctl|Tdie|Package id' /sys/class/hwmon/hwmon*/temp*_label | head -n1 | cut -d':' -f1 | sed 's/label/input/' | xargs cat

# Following script outputs current cpu die temperature in milidegree-celcius, convert it to celcius and fahrenheit and display as:
#
# Celcius: 42.0 C
# Fahrenheit: 107.6 F


# Extract CPU die temperature in millidegree Celsius
die_temp_milli=$(grep -E 'Tctl|Tdie|Package id' /sys/class/hwmon/hwmon*/temp*_label | head -n1 | cut -d':' -f1 | sed 's/label/input/' | xargs cat)

# Convert millidegree Celsius to Celsius
die_temp_celsius=$(echo "scale=2; $die_temp_milli / 1000" | bc)

# Convert Celsius to Fahrenheit
die_temp_fahrenheit=$(echo "scale=2; $die_temp_celsius * 9 / 5 + 32" | bc)

# Output the temperatures in the desired format
echo "Celsius: $die_temp_celsius C"
echo "Fahrenheit: $die_temp_fahrenheit F"

0 comments on commit 0459793

Please sign in to comment.