-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemp
More file actions
executable file
·38 lines (32 loc) · 1.11 KB
/
temp
File metadata and controls
executable file
·38 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
preferred_types=("x86_pkg_temp" "core" "cpu" "package id 0" "Tctl")
# First, try to find a thermal zone with a preferred CPU-related type
for zone in /sys/class/thermal/thermal_zone*; do
type_path="$zone/type"
temp_path="$zone/temp"
if [[ -r "$type_path" && -r "$temp_path" ]]; then
type=$(<"$type_path")
temp=$(<"$temp_path")
for keyword in "${preferred_types[@]}"; do
if [[ "${type,,}" == *"${keyword,,}"* && "$temp" =~ ^[0-9]+$ && "$temp" -gt 1000 ]]; then
celsius=$((temp / 1000))
echo "{\"text\": \" ${celsius}°C\", \"tooltip\": \"CPU Temp: $type ($zone)\"}"
exit 0
fi
done
fi
done
# Fallback: any readable temp above 30°C
for zone in /sys/class/thermal/thermal_zone*; do
temp_path="$zone/temp"
if [[ -r "$temp_path" ]]; then
temp=$(<"$temp_path")
if [[ "$temp" =~ ^[0-9]+$ && "$temp" -gt 30000 ]]; then
celsius=$((temp / 1000))
echo "{\"text\": \" ${celsius}°C\", \"tooltip\": \"Fallback zone: $zone\"}"
exit 0
fi
fi
done
# Final fallback
echo '{"text": "N/A", "tooltip": "No valid CPU thermal zone found"}'