forked from iiitl/bash-practice-repo-24
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iiitl#8 CPU die temperature in Celsius and Fahrenheit
Bash Script to get the cpu temperature in milli celsius and then convert it to celsius and fahrenheit
- Loading branch information
1 parent
d18e2cf
commit 0459793
Showing
1 changed file
with
14 additions
and
1 deletion.
There are no files selected for viewing
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
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" |