Originally posted by cookie_ie
I want to show the number of users logged on at one time
Just the command "who" will give you all users currently logged in. But it will print the same user more than once if (s)he is logged in more than once.
If you want unique logged in user:
who | cut -d' ' -f1 | sort | uniq
Add the "-c" option to "uniq" to count the number of times each user is logged in:
who | cut -d' ' -f1 | sort | uniq -c
[...] and the number of users in the same group logged on, is all this possible?
Here's a long one-liner that does this:
who | cut -d' ' -f1 | sort | uniq | xargs groups | sed -e 's/.*: \(.*\)/\1/' -e 's/ /\n/g' | sort | uniq -c
It prints something like:
Which means there are 2 user logged in who are member of the group "disk". this is for unique usernames, i.e. if "heiko' is member of "dialout", and "heiko" is logged in 5 times, it will only print "1 dailout". I you want it to print "5 dailout" in this case, remove the first "sort | uniq":
who | cut -d' ' -f1 | xargs groups | sed -e 's/.*: \(.*\)/\1/' -e 's/ /\n/g' | sort | uniq -c
Which printed in the same situation on my computer:
Note: All commands above do not
count/print user sessions started with the "su" command.