Hey,
You need the '-b' Option for top, because it's not for the Terminal.
We talked long about that in the IRC Channel, we came to this:
top -b -d 1 -n 2|grep Cpu|awk 'BEGIN { FS = " " } { print $2 }'|tail
-n 1 | sed 's/us,//g')
This should echo the right cpu usage...top -n 1 seems to be not
right(sometimes?).
We also had another Way of doing it, probably more reliable, but i am
sorry, i can't tell you that. It has to do something with /proc/stat,
but for me this was enough.
2009/5/5, Jesús Gabriel y Galán <jgabrielygalan_AT_gmail.com>:
> Hi,
>
> I was trying to modify the status bar to add cpu % usage. The easiest
> way I found (or so I thought) was this, which works in the command
> line:
>
> jesus_AT_localhost:~$ top -n 1 | awk 'NR==3 {print $2}'
> 1.9%us,
>
> (I will massage $2 later to remove the us and the comma, but for now
> it was enough as a test),
> but when I add it like this to my wmiirc:
>
> status() {
> echo -n $(acpi) '|' $(top -n 1 | awk 'NR==3 {print $2}') '|'
> $(uptime | sed 's/.*://; s/,//g') '|' $(date)
> }
>
> it doesn't work. It shows an empty space between the two |. (the
> status function is the one called in the original wmiirc)
> Anybody can give a hint at what might be going on, or have a better
> idea on how to show the cpu % usage?
>
> Thanks,
>
> Jesus.
>
>
Received on Tue May 05 2009 - 17:16:18 UTC
This archive was generated by hypermail 2.2.0 : Tue May 05 2009 - 17:24:08 UTC