- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to generate a report with the last login date ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2011 10:17 AM
тАО06-09-2011 10:17 AM
How to generate a report with the last login date of all accounts (non-trusted system)
What I'm after is to find out how login(1) works when it displays something like:
"Last login: Tue Apr 12 13:45:05 2011 from hq-it-8skk8f1.h"
I think the login(1) program reads wtmp and get this information from it. And it does it so fast!
Using last(1) on a user account not only takes forever but also lists all the entries (not the last one) so it makes it unpractical/cumbersome for the type of report I'm trying to generate.
How does login(1) works so that it can display this information when one logins?
Is it using getut(3) or something like that?
Could you please help?
Thanks,
Manuel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2011 10:57 AM
тАО06-09-2011 10:57 AM
Re: How to generate a report with the last login date of all accounts (non-trusted system)
As far as I know, the information you see comes from the '/var/adm/wtmp' file and would likely be sought using the 'getutent()' library routines.
The likely difference between the speed you get during login when compared to running 'last(1M)' is that (1) you are not doing very slow I/O to your terminal; and (2) with 'last()' although the reading is backwards through the file it is through the entire file.
If the only thing of interest is the most recent login information, reading backwards until a match for the login name is found, followed by an immediate return of that information without further I/O would be very quick.
Regards!
...JRF...
- Tags:
- wtmps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2011 11:54 AM
тАО06-09-2011 11:54 AM
Re: How to generate a report with the last login date of all accounts (non-trusted system)
Many thanks for your insightful answer.
I've got a question. In wtmp how do you know how to distinguish between LOGIN/LOGOUT events?
By looking at wtmp(4)it's not completely clear to me how one could distinguish a LOGIN event from a LOGOUT.
Do you know how to tell?
Thanks for your help,
Manuel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2011 12:14 PM
тАО06-09-2011 12:14 PM
Re: How to generate a report with the last login date of all accounts (non-trusted system)
If I recall correctly you want to match up 'ut_type' of 7 (USER_PROCESS) and 8 (DEAD_PROCESS). You can see this if you do:
# /usr/sbin/acct/fwtmp < /var/adm/wtmp > /tmp/mywtmp
...and examine '/tmp/mywtmp'.
Look at '/usr/include/utmp.h' too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2011 01:11 PM
тАО06-09-2011 01:11 PM
Re: How to generate a report with the last login date of all accounts (non-trusted system)
Actually somebody in HP suggested that I could also use:
# last -1
But the advantage to use fwtmp(1M) IMHO is that you get the nice epoch time and you could do nice things like:
if curr_epoch_time - last_logged_in_epoch_time > 90*86400 ; then
print "User hasn't logged in the last 90 days"
fi
So basically by only grabbing entries of type 7, tac(1)'ing the file, parsing the file and exiting as soon as a username match is found, could possibly do the trick.
Thanks again!
Manuel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2011 01:21 PM
тАО06-09-2011 01:21 PM
Re: How to generate a report with the last login date of all accounts (non-trusted system)
> So basically by only grabbing entries of type 7, tac(1)'ing the file, parsing the file and exiting as soon as a username match is found, could possibly do the trick.
That should work. A nice use of 'tac' (from the open-source world) too!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2011 07:48 AM
тАО06-14-2011 07:48 AM
Re: How to generate a report with the last login date of all accounts (non-trusted system)
After poking around with this I decided to create a small C program to grab what I wanted from /var/adm/wtmp. I used and modified code from Miquel van Smoorenburg's last(1) Linux implementation.
Makefile contents:
CC = cc
CFLAGS = +w1 -s -D _LARGEFILE_SOURCE
The program returns a semicolon delimited field single line, with ut_user, ut_type, ut_time and ctime(ut_time) of the last time the user provided in argv[1], logged into the system according to the WTMP_FILE.
Return values for main/program:
0 -> a record was found
1 -> no record was found
2 -> WTMP_FILE/Usage error may have occured
Example:
# ./lastLogged root
root;7;1307634320;Thu Jun 9 11:45:20 2011
Hopefully it will be useful for somebody else.
Thanks,
Manuel