Google
 
2008-09
12

one simple shell CGI script

Filed under: Tech articles — woojar @ 3:01 pm

Recently I want to learn further the shell programming. So just make the script to get the CPU usage rate.

#!/bin/bash
INPUT=/proc/stat
INTERVAL=1;

GetLoad(){
T2=`sed -n “1″p $INPUT |awk ‘{ print $2+$3+$4+$5+$6+$7+$8 }’`;
A2=`sed -n “1″p $INPUT |awk ‘{print $5}’`
}

GetLoad;
A1=$A2
T1=$T2
sleep $INTERVAL
GetLoad
A=$(($A2-$A1))
T=$(($T2-$T1))

echo “contentType: text/html”
echo “”
#echo “”
#echo “”
#echo “”
#echo “”
#echo “”

echo $A $T |awk ‘{printf “%.2f\n”,$1/$2}’

#echo “”
#echo ““

Tags: ,

Related posts

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

35 queries. 0.334 seconds. Powered by WordPress
沪-ICP备07003363号 Stat.