dev/bash/cpu/cpu.sh

16 lines
397 B
Bash
Executable File

#!/bin/bash
# cpu usage
a=`cat /proc/stat|grep cpu|head -n1|sed -r 's/[0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+/Z&Z/'|cut -dZ -f2`
sleep 1
b=`cat /proc/stat|grep cpu|head -n1|sed -r 's/[0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+/Z&Z/'|cut -dZ -f2`
sum=0
for i in `seq 3`; do
s1="`echo $a|cut -d" " -f$i`"
s2="`echo $b|cut -d" " -f$i`"
sum=$sum+$s2-$s1
done
echo $sum|bc