Quote:
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:
Code:
who | cut -d' ' -f1 | sort | uniq
Add the "-c" option to "uniq" to count the number of times each user is logged in:
Code:
who | cut -d' ' -f1 | sort | uniq -c
Quote:
[...] and the number of users in the same group logged on, is all this possible?
|
Here's a long one-liner that does this:
Code:
who | cut -d' ' -f1 | sort | uniq | xargs groups | sed -e 's/.*: \(.*\)/\1/' -e 's/ /\n/g' | sort | uniq -c
It prints something like:
Code:
1 audio
1 cdrom
1 dialout
2 disk
1 heiko
1 video
1 weg
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":
Code:
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:
Code:
5 audio
5 cdrom
5 dialout
6 disk
5 heiko
5 video
1 weg
Note: All commands above
do not count/print user sessions started with the "su" command.