![如何合并这两个跟踪脚本的输出](https://linux22.com/image/179619/%E5%A6%82%E4%BD%95%E5%90%88%E5%B9%B6%E8%BF%99%E4%B8%A4%E4%B8%AA%E8%B7%9F%E8%B8%AA%E8%84%9A%E6%9C%AC%E7%9A%84%E8%BE%93%E5%87%BA.png)
我有2个脚本:
track_temps.sh
while true
do
echo -n "$(date +"%H:%M:%S"): "
sensors | grep Tdie
# Sleeping for X seconds
sleep 1
done
track_mhz.sh
while true
do
# Printing the time and all temperatures to stdout
echo -n "$(date +"%H:%M:%S"): "
cat /proc/cpuinfo | grep "MH" | sort -r | head -1
# Sleeping for X seconds
sleep 1
done
track_temps.sh 的输出如下所示:
09:31:44: Tdie: +69.1°C (high = +70.0°C)
09:31:45: Tdie: +69.1°C (high = +70.0°C)
09:31:46: Tdie: +69.1°C (high = +70.0°C)
track_mhz.sh 的输出如下所示:
09:32:01: cpu MHz : 4015.803
09:32:02: cpu MHz : 4008.034
09:32:03: cpu MHz : 4028.516
我想合并输出,使其看起来像
09:31:44: Tdie: +69.1°C (high = +70.0°C) cpu MHz: 4015.803
09:31:45: Tdie: +69.1°C (high = +70.0°C) cpu MHz: 4008.034
09:31:46: Tdie: +69.1°C (high = +70.0°C) cpu MHz: 4028.516
更好的是,会是
答案1
我会尝试
while true
do
echo -n "$(date +"%H:%M:%S"): "
echo -n "$(sensors | grep Tdie) "
awk '$2 == "MHz" { if (c< $4) c=$4;} END {printf "cpu MHz %s\n",c}' /proc/cpuinfo
sleep 1
done
- 在我的盒子上,CPU 频率从 998 MHz 更改为 1200 MHz,我不确定
sort -r
是否会按预期运行。 (字符串“900”大于字符串“1200”)