Created
June 9, 2025 01:04
-
-
Save 4Ply/3aafeabc4f2b81f64c28a4c5c23a6f0e to your computer and use it in GitHub Desktop.
Show /etc/fancontrol in a more human-readable format
This file contains hidden or 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 | |
| awk ' | |
| BEGIN { | |
| FS = "="; | |
| section_order[1] = "CURRENT"; | |
| section_order[2] = "MINTEMP"; | |
| section_order[3] = "MAXTEMP"; | |
| section_order[4] = "MINPWM"; | |
| section_order[5] = "MINSTART"; | |
| section_order[6] = "MINSTOP"; | |
| section_order[7] = "FCTEMPS"; | |
| section_order[8] = "FCFANS"; | |
| COMMENT["MINTEMP"] = "Below this, the fan can run at minimum speed"; | |
| COMMENT["MAXTEMP"] = "Fan reaches full speed at this point" | |
| COMMENT["MINPWM"] = "Fan’s lowest reliable speed without stalling"; | |
| COMMENT["MINSTART"] = "PWM value needed to reliably start the fan from a stop"; | |
| COMMENT["MINSTOP"] = "PWM below this stops the fan. This should be a bit lower than MINSTART"; | |
| } | |
| { | |
| if ($1 ~ /^#/) next; | |
| if ($1 ~ /^INTERVAL/) next; | |
| section = $1; | |
| value = substr($0, index($0, "=")+1); | |
| n = split(value, arr, " "); | |
| for (i = 1; i <= n; i++) { | |
| split(arr[i], kv, "="); | |
| if (length(kv[2]) > 0) { | |
| data[kv[1]][section] = kv[2]; | |
| } else { | |
| data[kv[1]][section] = ""; # for single values | |
| } | |
| } | |
| } | |
| END { | |
| print "==== device list ====\n"; | |
| for (dev in data) { | |
| if (dev ~ /\//) continue; # exclude fans | |
| print dev ":"; | |
| for (section in data[dev]) { | |
| printf " %-10s -> %s\n", section, data[dev][section]; | |
| } | |
| print ""; | |
| } | |
| print "==== fan configuration ====\n"; | |
| for (fan in data) { | |
| if (fan !~ /\//) continue; # only show fan data | |
| desc="" | |
| if (fan == "hwmon3/pwm2") desc=" (CPU)"; | |
| if (fan == "hwmon3/pwm7") desc=" (MOBO)"; | |
| if (fan == "hwmon3/pwm3") desc=" (Back of case)"; | |
| if (fan == "hwmon3/pwm4") desc=" (Side wall - top)"; | |
| if (fan == "hwmon3/pwm5") desc=" (Side wall - bottom)"; | |
| if (fan == "hwmon3/pwm6") desc=" (Side wall - middle)"; | |
| # get the current fan speed | |
| cmd="cat /sys/class/hwmon/" fan; | |
| cmd | getline current_value; | |
| close(cmd); | |
| data[fan]["CURRENT"]=sprintf("%d (%d%% power)", current_value, current_value/255*100); | |
| print fan desc ":"; | |
| for (so = 1; so in section_order; so++) { | |
| sec = section_order[so]; | |
| if (sec in data[fan]) { | |
| if (sec == "FCTEMPS" || sec == "FCFANS") { | |
| # get the value of the temp monitor | |
| cmd="cat /sys/class/hwmon/" data[fan][sec]; | |
| cmd | getline current_value; | |
| close(cmd); | |
| if (sec == "FCTEMPS") { | |
| current_value=current_value/1000 | |
| current_value=sprintf("%d °C", current_value) | |
| } | |
| line = sprintf("%-10s -> %s (%s)", sec, data[fan][sec], current_value); | |
| } else { | |
| line = sprintf("%-10s -> %s", sec, data[fan][sec]); | |
| } | |
| if (COMMENT[sec] != "") { | |
| printf " %-42s # %s\n", line, COMMENT[sec]; | |
| } else { | |
| printf " %-42s\n", line; | |
| } | |
| } | |
| } | |
| for (section in data[fan]) { | |
| found = 0; | |
| for (so = 1; so in section_order; so++) { | |
| if (section == section_order[so]) { | |
| found = 1; | |
| break; | |
| } | |
| } | |
| if (!found) { | |
| printf " %-10s -> %s\n", section, data[fan][section]; | |
| } | |
| } | |
| print ""; | |
| } | |
| } | |
| ' /etc/fancontrol |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example output: