Created
November 13, 2012 02:05
-
-
Save border/4063484 to your computer and use it in GitHub Desktop.
取得CPU利用率
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
##echo user nice system idle iowait irq softirq | |
CPULOG_1=$(cat /proc/stat | grep 'cpu ' | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}') | |
SYS_IDLE_1=$(echo $CPULOG_1 | awk '{print $4}') | |
Total_1=$(echo $CPULOG_1 | awk '{print $1+$2+$3+$4+$5+$6+$7}') | |
sleep 5 | |
CPULOG_2=$(cat /proc/stat | grep 'cpu ' | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}') | |
SYS_IDLE_2=$(echo $CPULOG_2 | awk '{print $4}') | |
Total_2=$(echo $CPULOG_2 | awk '{print $1+$2+$3+$4+$5+$6+$7}') | |
SYS_IDLE=`expr $SYS_IDLE_2 - $SYS_IDLE_1` | |
Total=`expr $Total_2 - $Total_1` | |
SYS_USAGE=`expr $SYS_IDLE/$Total*100 |bc -l` | |
SYS_Rate=`expr 100-$SYS_USAGE |bc -l` | |
Disp_SYS_Rate=`expr "scale=3; $SYS_Rate/1" |bc` | |
echo $Disp_SYS_Rate% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment