this is kind of a lame way to do it, but i think it should work for you:
top -n 1 -b -C -p 0|head -5|tail -1|awk '{print $9}'|tr -d '%'
Josh Coates
http://www.jcoates.org
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, October 13, 2004 1:30 PM
To: [EMAIL PROTECTED]
Subject: [uug] parsing some text
I'd like to get the system idle percentage from 'top' as a plain old number
this works some of the time:
top -n 1 -b -C -p 0 |xargs |/bin/awk '{print $41}'|tr -d '%'
if the top output looks like this:
------------------------------------------
11:32:25 up 5 days, 20 min, 4 users, load average: 0.38, 0.18, 0.06
1 processes: 0 sleeping, 1 running, 0 zombie, 0 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 0.4% 0.0% 0.2% 0.0% 0.0% 0.0% 99.2%
------------------------------------------
but if the output looks like:
------------------------------------------
11:33:52 up 7 days, 22:45, 5 users, load average: 0.00, 0.00, 0.00
1 processes: 0 sleeping, 1 running, 0 zombie, 0 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 1.4% 0.0% 0.2% 0.0% 0.0% 0.0% 98.3%
------------------------------------------
i'd have to use {print $40} because of the difference between
"11:33:52 up 7 days, 22:45" and "11:32:25 up 5 days, 20 min"
So, is there a nice scripty way to get that idle percentage that is more
consistant than my hack?
mrb
____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list