On Wed, Nov 13, 2002 at 10:50:18PM +1300, Michael Beattie wrote:
> top -b -n1 | grep "^Cpu(s):" | awk '{print $2+$4+$6}'
> 
> Of course, that is *HIDEOUSLY* specific to my top. (you want this line, or
> its equivalent:
> Cpu(s):   0.4% user,   0.1% system,   0.0% nice,  99.5% idle,   0.0% IO-wait
>   $1       $2   $3      $4   $5        $6   $7.. etc for awk fields)

Ok, after thinking about it, you need:

top -b -n2 | grep "^Cpu(s):" | tail -1 | awk '{print $2+$4+$6}'
(that works with procps 3.0.3)

top -b -n2 | grep "^CPU" | tail -1 | awk '{print $3+$5+$7}' 
for procps 2.0.8

You need two iterations of top, so that top correctly calculates for that
time segment. the first iteration is a little bogus....

Mike.
-- 
Michael Beattie <[EMAIL PROTECTED]>

CPU's dont tend to work very well after their "magic smoke" has escaped.

Reply via email to