?
Solved

User loged in twice

Posted on 2000-01-30
10
Medium Priority
?
327 Views
Last Modified: 2012-05-04
I'm looking for somthing that will tell me if a user is loged in twice and what port they are loged in on. In the example I would like it to tell me user1 is loged in twice.

I know I can view a who out put but would like to find something to do it for me from a cron or something like that.

My who output looks like this:

user1 ttyC26   Jan 30 11:03
user2 ttyC27   Jan 30 10:51
user3 ttyC15   Jan 30 10:55
user1 ttyC28   Jan 30 11:02
0
Comment
Question by:bross073097
  • 3
  • 2
  • 2
  • +2
10 Comments
 

Expert Comment

by:Vile
ID: 2443141
I just did something like this for an assignment in school. :) I can tell you a method of doing it in C. All login information is saved in a file called utmp. if you load the header file for utmp structure you can read the utmp file and extract the user name. If it appears more than once it will be in there.
0
 

Expert Comment

by:Vile
ID: 2443182
if you give me a little bit I can write the program to do it and share the code.
0
 

Author Comment

by:bross073097
ID: 2443342
Great!! If you need any other information let me know.

Thanks
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:mliberi
ID: 2460643
who | cut -f1 -d' ' | sort | uniq -c | grep -v '^   1'

will give you a list of users logged in more than once.
0
 

Author Comment

by:bross073097
ID: 2463901
That gave me a list of everyone with a 1 infront of them.

Thanks
Bob Rosss
0
 
LVL 3

Expert Comment

by:mliberi
ID: 2481334
I tested the command on an AIX box, so little changes may be needed.

Proceed step by step and eventually change the command to get it working.

1) who|cut -f1 -d' '
note the space between quotes.
output should be a list of user names

2) who|cut -f1 -d' '|sort
the same list sorted. Multiple instances of the same user name should appear in adjacent lines

3) who|cut -f1 -d' '|sort|uniq -c
each user name compares in the output only once with the number of occurrences

4) who|cut -f1 -d' '|sort|uniq -c|grep -v '^   1'
discard from the previous list users appearing only once. Note the '^' meaning start of line, and count spaces before '1' (in AIX it is three, Linux uniq command may output a different number of leading spaces)

P.S. I checked 'uniq -c' output on a Red Hat 6.0 Linux system: there are six leading blanks. So the last command in the pipe should be grep -v '^      1'

enjoy
0
 

Author Comment

by:bross073097
ID: 2540078
I agreed to wait for Vile to write a small program to do what I asked. He still hasn't sent anything yet, but I will give him more time to allow someone else the chance.

Thanks
Bob Ross
0
 
LVL 1

Expert Comment

by:hansendc
ID: 2570147
Try This:

who | awk '{print $1}' | sort | uniq -c | awk '{print $1 " " $2}' | grep -v ^"1"

The awk helps to format the input.  It will remove the spaces problem.  Run that through awk one more time to only get the usernames and not number of logins.  

This gives just the logins, not the number of times logged in AND the login.

who | awk '{print $1}' | sort | uniq -c | awk '{print $1 " " $2}' | grep -v ^"1"
 | awk '{print $2}'

I can explain it all if you want.
0
 
LVL 1

Accepted Solution

by:
hansendc earned 900 total points
ID: 2570148
Try This:

who | awk '{print $1}' | sort | uniq -c | awk '{print $1 " " $2}' | grep -v ^"1"

The awk helps to format the input.  It will remove the spaces problem.  Run that through awk one more time to only get the usernames and not number of logins.  

This gives just the logins, not the number of times logged in AND the login.

who | awk '{print $1}' | sort | uniq -c | awk '{print $1 " " $2}' | grep -v ^"1"
 | awk '{print $2}'

I can explain it all if you want.
0
 
LVL 2

Expert Comment

by:Reinier
ID: 2601619
You don't need three awk invocations and you don't need to count spaces. Change mliberi's solution to this:

who | cut -f1 -d' ' | sort | uniq -c | grep -v '^  *1'

That is a hat, two spaces, a * and a 1 as the regexp for the last grep -v. It selects lines that begin with one or more spaces followed by a 1.

BTW, hansendc's one will not show a username if it happens to have a 1 in it. I guess that's not what you want.

Don't you love the command line?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question