Not getting full name of last logged-in user in linux


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Not getting full name of last logged-in user in linux
# 1  
Old 12-23-2011
Not getting full name of last logged-in user in linux

last unix command shows the list of last logged-in users. But the usernames are trimmed to eight characters.

Is there any other way to get the full login name of last loggedin user ?

I tried lastlog command, but this command not listing user info in some machines.
# 2  
Old 12-23-2011
Which Unix and what version are you talking about?
# 3  
Old 12-23-2011
lastlog works on Linux, but on most commercial UNIX systems like Solaris, this is not included. But, you can easily make a shell script to compare output of last with /etc/passwd. You need to tell us what exactly you are trying to do, so that we can help you better.

This is my quick script which can tell you who all logged on to the system and their last logon time, obviously the rest of the user listed in /etc/passwd file never logged in:

Code:
last | awk '{print $1}' | sort | uniq | sed -e '/^$/d; /^wtmp/d' | while read i; do last | grep $i | tail -1; done


Last edited by admin_xor; 12-23-2011 at 12:10 PM..
# 4  
Old 12-23-2011
In most versions of unix the maximum length of the username field is 8 characters. Longer username fields can be allowed but the effects are unpredictable.
See on your unix system:
Code:
man 4 passwd

It could be quite different for your Linux.

Btw. If you have the "fwtmp" utility it should display whatever is in the wtmp file.

Last edited by methyl; 12-23-2011 at 02:27 PM..
# 5  
Old 12-26-2011
not getting full name of last logged-in user in linux

Hi Everyone,

Thank you for your replies.

I try to identify the owner of a linux machine with login history. I used last unix command to get the list,parse and get the first username from the list. This is my assumption. But last command shows only 8 characters and i am looking for some other solution to my problem. Sorry for not explain this in my previous post.

Please let me know, is there any alternate way to find the owner (one of the login names) in linux machines.

I have this issue in Redhat 8+,Ubuntu-10.X and in Mandriva 2010 version
# 6  
Old 12-26-2011
You have to use last with -w switch which shows the full logon id of a user:
Code:
last -w

I do not think there's any other way of checking the owner of the machine. But, the files where the last command checks gets the information (/var/log/wtmp) can be deleted by a log maintenance program like logrotate. So, you may want to verify the first login time of the suspected machine owner with the "modify" time of one of the files like .profile or .bash_profile in root's home directory /root. These files get created when the root account gets created i.e during the installation. If nobody has changed the content of these files, the modify time will be the same as the file creation time.
Code:
# stat /root/.bash_profile
  File: `/root/.bash_profile'
  Size: 176             Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 795840      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2011-11-22 18:21:32.962989477 -0800
Modify: 2009-05-20 03:45:02.000000000 -0700
Change: 2011-11-21 04:15:47.124320704 -0800

These are not convenient ways of determining the exact owner of the machine. But, still you can work your way out with these. If you are working on production environment, I would suggest that you implement a schema for each ID creation and tag the IDs with information like who requested for that ID, etc.

Hope this helps.
# 7  
Old 12-26-2011
Thank you for your suggestion. I will try at my end.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Last user logged in

hi! How can I find into: /var/log/messages.4 /var/log/messages.3 /var/log/messages.2 /var/log/messages.1 /var/log/messages The last user do a login? (for example user1) My idea is to search by the pattern "Accepted password for" buy I necessary search into all files first and in the... (2 Replies)
Discussion started by: guif
2 Replies

2. Shell Programming and Scripting

current logged in user

Hey guys I need a script that reads a login name and verifies if that user is currently logged in i have found few commands like "who" and "users" but i wonder how can i verify it that login name is logged in or not? (3 Replies)
Discussion started by: nishrestha
3 Replies

3. Red Hat

How to confirm an user logged in is a remote user?

How do I confirm if a user logged in, is remote or local? In the case if the user is remote, how to be sure what authentication/method is it using, like LDAP, NIS or other? (2 Replies)
Discussion started by: kirtikjr
2 Replies

4. Shell Programming and Scripting

Does running a cron job of a user require the user to be logged in?

Suppose user 'asdf' is not logged into server 'bbbb', but the server is up. User 'asdf' has cron job. Will it be executed? (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

5. Shell Programming and Scripting

User Logged In The Most - Bash

Hi, first time poster, newbie to Bash. I'm looking to get the username of the user who's been logged into a computer the most / longest. I am new to Bash but am familiar with other scripting languages, mainly PHP. So I have a general idea about how to go about the script logic, but don't know... (13 Replies)
Discussion started by: Panman82
13 Replies

6. Shell Programming and Scripting

How can one know how much time user logged?

Hello, i know who command gives you the time when particular user logged in. And subtracting today's date and time from the one found in who we can get how much time user logged in. But this can get very much clumsy as we can't subtract date directly in unix . Is there any other way or command... (4 Replies)
Discussion started by: salman4u
4 Replies

7. UNIX for Advanced & Expert Users

Send email as a different user than the user logged in

Hi I am using mailx to send email and am wondering if there is a way I can send the email from a different user than the user logged in. something like do-not-reply@xyz.com Thank you. (1 Reply)
Discussion started by: rakeshou
1 Replies

8. Shell Programming and Scripting

script on user who logged in????

writing a script that will check every 5 seconds whether a particular user has logged into the system # Determine if someone is logged on # Version 4.0 if then echo “ Incorrect number of arguments” echo “Usage: $ ison4 <user>” else user=“$1” if who | grep “$user” > /dev/null then... (2 Replies)
Discussion started by: kim187
2 Replies

9. Shell Programming and Scripting

user logged on?

Hi, What commands do i need to check if a user is logged on to the network? thanks. (1 Reply)
Discussion started by: provo
1 Replies

10. UNIX for Dummies Questions & Answers

Is user logged on??

How can i check to see if a user is logged on to the network? (1 Reply)
Discussion started by: provo
1 Replies
Login or Register to Ask a Question