LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to count number sessions of users? (https://www.linuxquestions.org/questions/linux-general-1/how-to-count-number-sessions-of-users-4175451655/)

wwinay 02-25-2013 02:10 PM

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....

Kustom42 02-25-2013 02:12 PM

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.

wwinay 02-25-2013 02:24 PM

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

Kustom42 02-25-2013 02:26 PM

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.

273 02-25-2013 02:26 PM

OK, this is the fourth thing an "experienced Linux user" has asked without googling first or showing some attempt at it.
What gives?

Kustom42 02-25-2013 02:27 PM

Quote:

Originally Posted by 273 (Post 4899513)
OK, this is the fourth thing an "experienced Linux user" has asked without googling first or showing some attempt at it.
What gives?

I agree, someone with an RHCE should be able to do this with their eyes closed.

schneidz 02-25-2013 02:52 PM

w and/or who will get you at least part of the way there (just parse the output to your liking).

Kustom42 02-25-2013 02:55 PM

Quote:

Originally Posted by schneidz (Post 4899522)
w and/or who will get you at least part of the way there (just parse the output to your liking).

I was assuming he was already this far, I wanted him to post where he was at. You can use AWK to sum up and print out the number of sessions per user.

Habitual 02-25-2013 07:23 PM

Quote:

Originally Posted by wwinay (Post 4899510)
And I also completed RHCE certification.

You should ask for a refund.

lleb 02-25-2013 10:18 PM

Quote:

Originally Posted by Habitual (Post 4899693)
You should ask for a refund.

amen Habitual. this guy knows less then I do, and I dont know all that much.

Habitual 02-26-2013 10:16 AM

Quote:

Originally Posted by lleb (Post 4899789)
amen Habitual. this guy knows less then I do, and I dont know all that much.

Certifications, they must be giving them away.

What I don't know could fill a warehouse,
What I do know could fill an outhouse.

Peace!

fortran 02-28-2013 02:40 AM

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
who command prints number of logged in users
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
      3 bugzilla     
      1 Harrison
      5 James
      7 root
      2 user



All times are GMT -5. The time now is 05:34 AM.