#!/bin/bash

# this shell is used for cal the cpuusage. it is added into crontab.
# it will automatically  run once per minute
# no input parm.
# no return parm.
# the file /tmp/system/cpuusage is used for shell cli_switch_cpu.sh 

total=5
sum=0
i=0


while [ $i -lt $total ]
do
	sleep 1
    tmp=`top -b -n 1 |grep Cpu| awk '{print $2}'| awk -F'%' '{print $1}' |awk -F'.' '{print $1}'`
    sum=$(($sum+$tmp))
    i=$(($i+1))
done

echo -n $(($sum/$total)) > /tmp/system/cpuusage

exit 0

