8.26. Program: lastonWhen you log in to a Unix system, it tells you when you last logged in. That information is stored in a binary file called lastlog. Each user has their own record; UID 8 is at record 8, UID 239 at record 239, and so on. To find out when a given user last logged in, convert their login name to a number, seek to their record in that file, read, and unpack. Doing so with shell tools is hard, but with the laston program, it's easy. Here's an example: % laston gnat gnat UID 314 at Mon May 25 08:32:52 2003 on ttyp0 from below.perl.com The program in Example 8-9 is much newer than the tctee program in Example 8-8, but it's less portable. It uses the Linux binary layout of the lastlog file. You'll have to change this for other systems. Example 8-9. laston
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|