how to count number sessions of users?
Hello Tuxers,
Please help me out how to count the number of sessions of users who are logged into system. the output must be like : user1 3 sessions root 4 sessions user2 1 sesion And also help me out how to get this from shell scrips.. Thanking in advance.... |
Sounds like homework and we usually aren't going to write it for you as thats not very helpful to someone who is learning. We can help get you there if you are having troubles but you need to let us know where you are at. What have you done in trying to attempt this? Have you been able to get as far as getting a list of all the sessions on the server? That is your fist step and is very easy with built in binaries on the system.
|
I am not bigginer to linux. I have good knowledge about linux.And I also completed RHCE certification. Right now I have Linux project in our Institute. And this problem I've been got so please help me to find out the solution
|
So are you unable to get a list of the current users logged into the system? Post what code you have or what you have attempted and where you are stuck.
|
OK, this is the fourth thing an "experienced Linux user" has asked without googling first or showing some attempt at it.
What gives? |
Quote:
|
w and/or who will get you at least part of the way there (just parse the output to your liking).
|
Quote:
|
Quote:
|
Quote:
|
Quote:
What I don't know could fill a warehouse, What I do know could fill an outhouse. Peace! |
If you want to print number of logged in users with their number of sessions. You can print using command line.
Shell script can give you more Robust results considering all test cases. But this is a simple use of command line to print desired results. You want to print number of users with their number of sessions. Code:
$ who | cut -d " " -f1 | sort -n | uniq -c using cut command I have printed first column that is list of usernames using sort I have sorted the list alphabatically. using uniq, I have printed 'Group BY' of all users now you want to know the number of instances ,you can use use uniq -c Now output looks like: Code:
1 apache2 |
All times are GMT -5. The time now is 05:34 AM. |