我如何清理输出命令的bash脚本的输出

时间:2016-12-11 17:18:11

标签: bash

所以我有这个脚本。它输出服务器的临时数据。当你通常不在bash脚本中运行它时,它看起来像这样

#!/bin/bash

echo $(sensors -f)

sleep 20

done

它输出服务器的临时数据。当你通常不在bash脚本中运行它时,它看起来像这样

i5k_amb-isa-0000
Adapter: ISA adapter
Ch. 0 DIMM 0: +145.4°F  (low  = +221.0°F, high = +255.2°F)

Ch. 0 DIMM 1: +141.8°F  (low  = +221.0°F, high = +248.0°F)

Ch. 1 DIMM 0: +141.8°F  (low  = +221.0°F, high = +255.2°F)

Ch. 1 DIMM 1: +133.7°F  (low  = +221.0°F, high = +255.2°F)

Ch. 2 DIMM 0: +158.9°F  (low  = +221.0°F, high = +255.2°F)

Ch. 2 DIMM 1: +134.6°F  (low  = +221.0°F, high = +255.2°F)

Ch. 3 DIMM 0: +131.9°F  (low  = +221.0°F, high = +248.0°F)

Ch. 3 DIMM 1: +148.1°F  (low  = +221.0°F, high = +255.2°F)

coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +123.8°F  (high = +179.6°F, crit = +212.0°F)

Core 1:      +114.8°F  (high = +179.6°F, crit = +212.0°F)

Core 2:      +120.2°F  (high = +179.6°F, crit = +212.0°F)

Core 3:      +118.4°F  (high = +179.6°F, crit = +212.0°F)

coretemp-isa-0001
Adapter: ISA adapter
Core 0:      +127.4°F  (high = +179.6°F, crit = +212.0°F)

Core 1:      +118.4°F  (high = +179.6°F, crit = +212.0°F)

Core 2:      +118.4°F  (high = +179.6°F, crit = +212.0°F)

Core 3:      +118.4°F  (high = +179.6°F, crit = +212.0°F)

所以看起来很好。除非您使用脚本运行它,否则您将获得此功能。

i5k_amb-isa-0000 Adapter: ISA adapter Ch. 0 DIMM 0: temp1_input: 63.000 temp1_max: 124.000 temp1_min: 105.000 temp1_alarm: 0.000 Ch. 0 DIMM 1: temp2_input: 60.500 temp2_max: 120.000 temp2_min: 105.000 temp2_alarm: 0.000 Ch. 1 DIMM 0: temp3_input: 61.000 temp3_max: 124.000 temp3_min: 105.000 temp3_alarm: 0.000 Ch. 1 DIMM 1: temp4_input: 56.500 temp4_max: 124.000 temp4_min: 105.000 temp4_alarm: 0.000 Ch. 2 DIMM 0: temp5_input: 70.500 temp5_max: 124.000 temp5_min: 105.000 temp5_alarm: 0.000 Ch. 2 DIMM 1: temp6_input: 57.000 temp6_max: 124.000 temp6_min: 105.000 temp6_alarm: 0.000 Ch. 3 DIMM 0: temp7_input: 55.500 temp7_max: 120.000 temp7_min: 105.000 temp7_alarm: 0.000 Ch. 3 DIMM 1: temp8_input: 64.000 temp8_max: 124.000 temp8_min: 105.000 temp8_alarm: 0.000 coretemp-isa-0000 Adapter: ISA adapter Core 0: temp2_input: 50.000 temp2_max: 82.000 temp2_crit: 100.000 temp2_crit_alarm: 0.000 Core 1: temp3_input: 46.000 temp3_max: 82.000 temp3_crit: 100.000 temp3_crit_alarm: 0.000 Core 2: temp4_input: 49.000 temp4_max: 82.000 temp4_crit: 100.000 temp4_crit_alarm: 0.000 Core 3: temp5_input: 48.000 temp5_max: 82.000 temp5_crit: 100.000 temp5_crit_alarm: 0.000 coretemp-isa-0001 Adapter: ISA adapter Core 0: temp2_input: 54.000 temp2_max: 82.000 temp2_crit: 100.000 temp2_crit_alarm: 0.000 Core 1: temp3_input: 48.000 temp3_max: 82.000 temp3_crit: 100.000 temp3_crit_alarm: 0.000 Core 2: temp4_input: 48.000 temp4_max: 82.000 temp4_crit: 100.000 temp4_crit_alarm: 0.000 Core 3: temp5_input: 48.000 temp5_max: 82.000 temp5_crit: 100.000 temp5_crit_alarm: 0.000

与第一次输出相比,您是否看到这看起来不可读?那么如何在脚本中运行时获得的数据输出看起来就像我刚运行独立命令时得到的数据一样。

1 个答案:

答案 0 :(得分:1)

没关系,我只是使用手表传感器 - 这对于我正在做的事情非常有用。