如何合并这两个跟踪脚本的输出

如何合并这两个跟踪脚本的输出

我有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”)

相关内容