服务器是多核CPU,想具体统计某一时间段间隔1秒各CPU的频率,并且将同一时刻各CPU频率在文本中同一行展示。
shell脚本
创建一个cpu.sh脚本,内容如下:
#!/bin/bash
while true
do
cpu0=`sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq`
cpu1=`sudo cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq`
cpu2=`sudo cat /sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq`
cpu3=`sudo cat /sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq`
cpu4=`sudo cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq`
cpu5=`sudo cat /sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_cur_freq`
echo $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5 >>$1
sleep 1
done
若要统计一定时间的频率,可将上述脚本的while true
替换成for i in $(seq 1 n)
效果展示
在cpu.sh所在目录执行sh cpu.sh cpu.txt
查看结果tail -f cpu.txt