1 |
On Fri, Mar 2, 2012 at 3:23 PM, Tanstaafl <tanstaafl@×××××××××××.org> wrote: |
2 |
> On 2012-03-02 3:50 PM, Paul Hartman <paul.hartman+gentoo@×××××.com> wrote: |
3 |
>> |
4 |
>> On Fri, Mar 2, 2012 at 2:39 PM, Tanstaafl<tanstaafl@×××××××××××.org> |
5 |
>> wrote: |
6 |
>>> |
7 |
>>> On 2012-03-02 2:33 PM, Paul Hartman<paul.hartman+gentoo@×××××.com> |
8 |
>>> wrote: |
9 |
>>>> |
10 |
>>>> |
11 |
>>>> And you can use the --sort options for ps to sort by cpu or anything |
12 |
>>>> you like (see the manpage) |
13 |
>>> |
14 |
>>> |
15 |
>>> |
16 |
>>> Even better, thanks Paul... |
17 |
>>> |
18 |
>>> watch -n1 "ps aux --sort=-%cpu | gawk '{ if ( \$3> 1.0 ) { print } }'" |
19 |
>>> |
20 |
>>> does exactly what I want... |
21 |
>>> |
22 |
>>> Hmmm... is there an easy way to include the column headers? |
23 |
>> |
24 |
>> |
25 |
>> To build on Grant's suggestion: |
26 |
>> ps aux --sort %cpu | gawk 'NR==1; $3> 0' |
27 |
> |
28 |
> |
29 |
> Hmmm.. ok, this works beautifully, thanks! |
30 |
> |
31 |
> But when I tried to incorporate it into the watch command like the other |
32 |
> one: |
33 |
> |
34 |
> Original: |
35 |
> |
36 |
> watch -n1 "ps aux --sort=-%cpu | gawk '{ if ( \$3 > 1.0 ) { print } }'" |
37 |
> |
38 |
> Attempt at incorporating your command into this: |
39 |
> watch -n1 "ps aux --sort=-%cpu | gawk 'NR==1; $3 > 0'" |
40 |
> |
41 |
> it gives me a syntax error: |
42 |
> |
43 |
> Every 1.0s: ps aux --sort=-%cpu | gawk 'NR==1; > 0' |
44 |
> Fri Mar 2 |
45 |
> 16:19:01 2012 |
46 |
> |
47 |
> gawk: NR==1; > 0 |
48 |
> gawk: ^ syntax error |
49 |
> |
50 |
> Any ideas on how to get this working in the watch version |
51 |
> |
52 |
> Thanks Paul, this will be very useful to me... |
53 |
> |
54 |
|
55 |
Put a backslash before the $, it needs to be escaped in that context. |