分类: LINUX
2008-12-03 11:51:59
#!/bin/bash cpu=`top -n 1 | grep Cpu | awk -F: '{print $2}' | awk -F "[%,]+" '{print $1,$2,$3,$4,$5,$6,$7,$8}'` us=`echo $cpu | awk '{print $2}'` echo "us $us" sy=`echo $cpu | awk '{print $5}'` echo "sy $sy" ni=`echo $cpu | awk '{print $8}'` echo "ni $ni" id=`echo $cpu | awk '{print $11}'` echo "id $id" a=$(echo "$us+$ni+$sy"|bc) b=$(echo "$us+$ni+$sy+$id"|bc) used=`echo $a $b | awk '{printf "%.2f\n",100*($1/$2)}'` echo " cpu ratio $used" |