Uso: sensors | ./color_sensors.awk
Uso com o relógio: watch -c 'sensors | ./color_sensors.awk'
#!/usr/bin/awk -f
BEGIN {
DEFAULT_COLOR = "3[;m";
RED = "3[1;31m";
MAGENTA = "3[1;35m";
# CPU_thresholds
cpu_high = 60;
cpu_middle = 50;
# GPU_thresholds
gpu_high = 80;
gpu_middle = 70;
}
function colorize(temp, mid_trsh, high_trsh) {
new_color = "";
temp_number = temp;
gsub("[^0-9]","",temp_number);
gsub(".$","",temp_number);
if(temp_number >= high_trsh)
new_color = RED;
else if (temp_number >= mid_trsh)
new_color = MAGENTA;
return new_color temp DEFAULT_COLOR;
}
/Core/ { $3 = "\t" colorize($3, cpu_middle, cpu_high); }
/Physical id/ { $4 = "\t" colorize($4, cpu_middle, cpu_high); }
# Multiple spaces added for alignment here - "\t ".
/temp1/ { $2 = "\t " colorize($2, gpu_middle, gpu_high) " "; }
{ print; }