我正在使用的脚本如下:
#!/bin/bash
lla=$(top -n 1 | grep "load average" | awk '{print $13,$14,$15}')
mem_usage=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
now=`date`
cur_time=$(echo $now | awk '{print $4}')
for i in {1..60}
do
echo "System Performance Statistics at: "$cur_time | tee -a hp.txt
echo "Linux Load Average: "$lla | tee -a hp.txt
echo "Memory Usage: "$mem_usage | tee -a hp.txt
echo "" | tee -a hp.txt
sleep 3
done
结果:
System Performance Statistics at: 19:00:29
Linux Load Average: 0.13, 0.11, 0.14^[(B^[[m^[[39;49m^[[K
Memory Usage: 82.7672
标准输出根本不显示任何乱码。我需要更改什么?
最佳答案
在 top 命令中添加了 -b,它起作用了。
来自 man top
:
-b :Batch-mode operation
Starts top in Batch mode, which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the `-n' command-line option or until killed.
关于linux - 使用 tee 命令打印垃圾字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33426854/