-
Notifications
You must be signed in to change notification settings - Fork 0
/
fan-info.sh
executable file
·88 lines (75 loc) · 2.65 KB
/
fan-info.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
SysPrefix='/sys/class/thermal'
ReadSysFile() { # $1 sys filename to read not including $SysPrefix
declare -g Tmp=''
#echo -n 'y'
[[ -r "$D/$1" ]] && {
#echo -n 'z'
read -rst5 Tmp < "$D/$1"
}
}
ScanThermalZone() {
echo -n 'Scanning Thermal Zone: '
Idx=0
declare -g -a Name Type Current Max Other
for D in ${SysPrefix}/*; do
echo -n "."
Name[$Idx]=${D##*/}
[[ -r $D/type ]] && read -rst5 Type[$Idx] J < $D/type
[[ -r $D/cur_state ]] && read -rst5 Current[$Idx] J < $D/cur_state
[[ -r $D/max_state ]] && read -rst5 Max[$Idx] J < $D/max_state
[[ ${Type[$Idx]} == 'Processor' ]] && {
ReadSysFile 'device/path'
Name[$Idx]="${Tmp##*.} (${Name[$Idx]##*[a-z]})"
}
[[ ${Type[$Idx]} == 'Fan' ]] && {
ReadSysFile 'device/firmware_node/path'
Name[$Idx]="${Tmp##*.} (${Name[$Idx]##*[a-z]})"
ReadSysFile 'device/firmware_node/real_power_state'
Other[$Idx]="$Tmp"
}
[[ ${Type[$Idx]} == 'intel_powerclamp' ]] && {
ReadSysFile 'power/control'
Other[$Idx]="$Tmp"
}
[[ ${Type[$Idx]} == 'acpitz' ]] || \
[[ ${Type[$Idx]} == 'x86_pkg_temp' ]] && {
ReadSysFile 'temp'
Current[$Idx]="${Tmp:0:-3}.${Tmp: -3:-2}"
ReadSysFile 'policy'
Other[$Idx]="${Tmp}"
ReadSysFile 'power/control'
Other[$Idx]+=" - ${Tmp}"
}
(( Idx++ ))
done
echo ' - Done'
}
PrintType() { # $1 is Type regex
I=0
while (( I < ${#Type[@]} )); do
[[ ! ${Type[$I]} == ${1:-.*} ]] && { (( I++ )); continue; }
printf "| %-18s | %-16s | %5s | %3s | %20s |\n" "${Name[$I]}" "${Type[$I]}" "${Current[$I]}" "${Max[$I]}" "${Other[$I]}"
(( I++ ))
done
}
Print() {
Line='--------------------------------------------------------------------'
Printed=''
printf ",-%-18.18s-,-%-16.16s-,-%5.5s-,-%3.3s-,-%20.20s-,\n" $Line $Line $Line $Line $Line
printf "| %-18.18s | %-16.16s | %5.5s | %3.3s | %20.20s |\n" 'Name' 'Type' 'Now' 'Max' 'Other'
# printf "|-%-18.18s-|-%-16.16s-|-%3.3s-|-%3.3s-|\n" $Line $Line $Line $Line
for T in "${Type[@]}"; do
[[ "$Printed" =~ $T ]] && continue; # We have already printed that type
printf "|-%-18.18s-|-%-16.16s-|-%5.5s-|-%3.3s-|-%20.20s-|\n" $Line $Line $Line $Line $Line
PrintType "$T"
Printed+=" $T"
done
printf "'-%-18.18s-'-%-16.16s-'-%5.5s-'-%3.3s-'-%20.20s-'\n" $Line $Line $Line $Line $Line
}
Main() {
ScanThermalZone
Print
}
Main
exit