User loged in twice

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
bross073097Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VileCommented:
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
VileCommented:
if you give me a little bit I can write the program to do it and share the code.
0
bross073097Author Commented:
Great!! If you need any other information let me know.

Thanks
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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

will give you a list of users logged in more than once.
0
bross073097Author Commented:
That gave me a list of everyone with a 1 infront of them.

Thanks
Bob Rosss
0
mliberiCommented:
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
bross073097Author Commented:
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
hansendcCommented:
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
hansendcCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ReinierCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.