Link to home
Start Free TrialLog in
Avatar of mativare
mativare

asked on

summary field

Hi
Please help to create summary field, when the output displays as last line  for pcpu, pmem
 ps -efo user,pcpu,pmem,comm | grep root | nawk '{print $2,$3}'
It is nice to have Solaris 8 one liner, if very difficult then script.
Thanks.
Avatar of Hanno P.S.
Hanno P.S.
Flag of Germany image

Do you mean you want to have %CPU and %MEM being summed up and displayed as last line?

Maybe, this is what you are looking for:

# ps -efo user,pcpu,pmem,comm | grep oracle | nawk 'BEGIN {s1=0;s2=0}
  {print $2,$3; s1=s1+$2; s2=s2+$3}
END {printf("Totals: %d %d\n",s1,s2) }'
Sorry: Replace "oracle" with "root" -- that's the way I developed and tested it ...
Avatar of mativare
mativare

ASKER

excelent justunix!  but please make it searchable both by user and comm, right now comm cannot summarise . Obviously it can be script then with one argument comm or user.
ps -efo user,pcpu,pmem,comm | grep ping | nawk 'BEGIN {s1=0;s2=0}
  {print $2,$3,$4; s1=s1+$2; s2=s2+$3}
END {printf("Totals: %d %d\n",s1,s2) }'
What do you mean by "searchable" ?

Can you post some output -- how you would like to have the result?
Ok, please see grep there, I would like to put user or comm after grep. so it makes it more universal.
Sorry this bad writing , actually greppable maybe is the term.
Put ping running for a long and then try script.
I'm still not sure what you need :-(

Looking at the awk-Skript:
  # ps -efo user,pcpu,pmem,comm | grep ping | nawk 'BEGIN {s1=0;s2=0}
    {print $2,$3,$4; s1=s1+$2; s2=s2+$3}
  END {printf("Totals: %d %d\n",s1,s2) }'
you can see that the second, third and fourth field ($2, $3, $4) are being used (displayed) only.

Could you give some example input (output from "ps") and the result you'd like to see?
ps -efo user,pcpu,pmem,comm | grep sshd | nawk 'BEGIN {s1=0;s2=0}      {print $2,$3,$4; s1=s1+$2; s2=s2+$3}
  END {printf("Totals: %d %d\n",s1,s2) }'
0.0 0.3 /usr/lib/ssh/sshd
0.0 0.3 /usr/lib/ssh/sshd
0.0 0.3 /usr/lib/ssh/sshd
0.0 0.3 /usr/lib/ssh/sshd
0.0 0.3 /usr/lib/ssh/sshd
0.0 0.3 /usr/lib/ssh/sshd
0.0 1.3 /usr/lib/ssh/sshd
0.0 0.3 /usr/lib/ssh/sshd
0.1 0.9 /usr/lib/ssh/sshd
Totals: 0 1
Please see calculation error is 300%, second field is actually 3.3. It ignores numbers after comma.
ASKER CERTIFIED SOLUTION
Avatar of Hanno P.S.
Hanno P.S.
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial