Capture PRSTAT based on CPU usage percentage

Hi,
Recently i have write a simple script to capture CPU high usage based on prstat but i found out that it did capture correctly. I need to capture the rows that contains CPU usage more than 3%. Below line which i thought will capture CPU usage based CPU column in prstat(9th parameter) which is more than 3 % but if any process CPU usage more than 10% it did not capture.

prstat 5 1 |awk '{ if ($9 >= 3) print $0 }' > /export/home/oracle/testtharmen.txt

Try $9+0 (to convert it into a number).

1 Like

problem #2 is that /usr/bin/awk cannot read a number if a character is appended. Here in $9 a % character is appended. Work-around: /usr/bin/nawk
With the default print action

prstat 5 1 | nawk '($9+0 >= 3)'

The last line (summary) eventually matches. An extra condition excludes it

prstat 5 1 | nawk '($9+0 >= 3 && $1+0 > 0)'
1 Like

Hi Rudic and MadeInGermany,

Thanks guys. It seems working.
I also learn new things about awk and nawk different.:slight_smile: