0

Currently I am working in a remote environment where I would like to sort the number of users using up the most processes with the ps command.The only problem is; with my current command; the root user is not displayed which should be displayed. The first output is what I'm looking for, the latter is what I currently receive.

157 root
 12 apache
 11 brun1992
  4 bb
  2 postfix
  2 hart4492
  2 68
  1 USER
  1 sshd
  1 rpcuser

MY COMMAND:

 ps -eo user=|sort|uniq -c | head -n 10 | sort -r $1
         9 apache
         6 au6620
         5 ande7941
         4 cwen4344
         4 bb
         3 dagg9715
         2 evan8561
         2 brun1992
         2 alki2221
         1 dbus
2

This will work:

ps -eo user|sort|uniq -c|sort -gr

sort -gr is the key to it.

-g : Sort numerically.

  • That works like my command, but I still do not see the root, I feel like in my command it is only skipping the first line or something – BrandonW000 Feb 28 '17 at 5:35
  • @BrandonW000 does "ps -eo user" shows root user ? – Rakesh.N Feb 28 '17 at 5:37
  • I only get apache at the top, but root is running the most processes right? – BrandonW000 Feb 28 '17 at 5:40
  • @BrandonW000 try with this link serverfault.com/questions/706032/… btw which OS are you using? – Rakesh.N Feb 28 '17 at 5:42
  • @Rackesh.N Ubuntu – BrandonW000 Feb 28 '17 at 6:03
0

The problem is you have the head before the sort. I think you are trying to find the top ten used usernames. First, as @rakesh-n says, you need to sort numerically.

But the problem is you get a list out of uniq that is sorted by username and then you take the top ten and only after that you sort by count. Have a look at your example and notice all the usernames start with a-e

ps -eo user=|sort|uniq -c | sort -r $1 | head -n 10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.