shell脚本 读取linux CPU占用率
脚本:for((i=1;i<=5;));docpu_us=`top -bn 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $3}'`cpu_sy=`top -bn 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $5}'`#echo $cpu_us#echo $cpu_sycpu_sum=$(echo "$cp
·
脚本:
for((i=1;i<=5;));
do
cpu_us=`top -bn 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $3}'`
cpu_sy=`top -bn 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $5}'`
#echo $cpu_us
#echo $cpu_sy
cpu_sum=$(echo "$cpu_us+$cpu_sy"|bc)
nowdate=$(date +"%Y-%m-%d %H:%M:%S")
echo "$nowdate CPU_SUM: $cpu_sum%" >> ./cpu.log
sleep 120
done
挂载到后台启动:
nohup sh cpu.sh >/dev/null 2>&1 &
查看cpu.log文件,会发现每隔两分钟会写入一次CPU占用百分比
更多推荐
已为社区贡献1条内容
所有评论(0)