LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-25-2013, 02:10 PM   #1
wwinay
LQ Newbie
 
Registered: Aug 2011
Posts: 8

Rep: Reputation: Disabled
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....
 
Old 02-25-2013, 02:12 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,588

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
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.
 
Old 02-25-2013, 02:24 PM   #3
wwinay
LQ Newbie
 
Registered: Aug 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
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
 
Old 02-25-2013, 02:26 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,588

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
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.
 
Old 02-25-2013, 02:26 PM   #5
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,413

Rep: Reputation: 794Reputation: 794Reputation: 794Reputation: 794Reputation: 794Reputation: 794Reputation: 794
OK, this is the fourth thing an "experienced Linux user" has asked without googling first or showing some attempt at it.
What gives?
 
1 members found this post helpful.
Old 02-25-2013, 02:27 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,588

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Quote:
Originally Posted by 273 View Post
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.
 
Old 02-25-2013, 02:52 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,094

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
w and/or who will get you at least part of the way there (just parse the output to your liking).
 
Old 02-25-2013, 02:55 PM   #8
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,588

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Quote:
Originally Posted by schneidz View Post
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.
 
Old 02-25-2013, 07:23 PM   #9
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,480
Blog Entries: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by wwinay View Post
And I also completed RHCE certification.
You should ask for a refund.
 
Old 02-25-2013, 10:18 PM   #10
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,555

Rep: Reputation: 463Reputation: 463Reputation: 463Reputation: 463Reputation: 463
Quote:
Originally Posted by Habitual View Post
You should ask for a refund.
amen Habitual. this guy knows less then I do, and I dont know all that much.
 
Old 02-26-2013, 10:16 AM   #11
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,480
Blog Entries: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by lleb View Post
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!
 
Old 02-28-2013, 02:40 AM   #12
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 50
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
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count characters and list down the number bison72 Linux - Newbie 3 01-22-2013 10:34 AM
Number of current sessions for user neel_learning_linux Linux - Newbie 5 05-13-2009 03:14 PM
count number of used ports mnchur Linux - General 2 02-10-2009 02:11 PM
How to get a Bash to count user sessions without WC Bamahut Programming 5 07-16-2008 06:52 AM
how to count the number of occurrences of a process beeblequix Linux - General 3 09-18-2006 04:17 PM


All times are GMT -5. The time now is 12:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration