センサー
を使用しています コンソールのCPU温度を監視します。これは出力の一部です:
coretemp-isa-0001
Adapter: ISA adapter
Physical id 1: +45.0°C (high = +80.0°C, crit = +90.0°C)
Core 0: +39.0°C (high = +80.0°C, crit = +90.0°C)
Core 1: +39.0°C (high = +80.0°C, crit = +90.0°C)
Core 2: +40.0°C (high = +80.0°C, crit = +90.0°C)
Core 3: +38.0°C (high = +80.0°C, crit = +90.0°C)
Core 4: +40.0°C (high = +80.0°C, crit = +90.0°C)
Core 8: +39.0°C (high = +80.0°C, crit = +90.0°C)
Core 9: +38.0°C (high = +80.0°C, crit = +90.0°C)
Core 10: +38.0°C (high = +80.0°C, crit = +90.0°C)
Core 11: +39.0°C (high = +80.0°C, crit = +90.0°C)
Core 12: +39.0°C (high = +80.0°C, crit = +90.0°C)
nouveau-pci-0200
Adapter: PCI adapter
GPU core: +0.92 V (min = +0.92 V, max = +1.00 V)
fan1: 2220 RPM
temp1: +48.0°C (high = +95.0°C, hyst = +3.0°C)
(crit = +105.0°C, hyst = +5.0°C)
(emerg = +135.0°C, hyst = +5.0°C)
この出力を「色付け」したいと思います。特に、気温が一定のしきい値を超えている場合は、赤で表示してほしい。したがって、たとえば、しきい値が60の場合、+60.0°C
が発生するとします。 、+61.0°Cコード> 、
+62.0°C
、などは赤で表示する必要があります(理想的には、2つの異なるしきい値に基づいたオレンジレベルと赤レベルが必要ですが、1レベルのソリューションも最適です)。理想的には、これは時計センサー
でも機能するはずです 。
承認された回答:
使用法: センサー| ./color_sensors.awk
時計での使用: watch-c'センサー| ./color_sensors.awk'
#!/usr/bin/awk -f
BEGIN {
DEFAULT_COLOR = "\033[;m";
RED = "\033[1;31m";
MAGENTA = "\033[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; }
結果: