home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / aix / 13110 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.4 KB  |  66 lines

  1. Newsgroups: comp.unix.aix
  2. Path: sparky!uunet!spillman!tye
  3. From: tye@spillman.uucp (E. Tye McQueen)
  4. Subject: Re: last command?
  5. Message-ID: <1993Jan07.210317.25025@spillman.uucp>
  6. Date: Thu, 07 Jan 1993 21:03:17 GMT
  7. References: <9301060106.AA10395@ecnet.ec> <1993Jan6.131057.23213@eagle.lerc.nasa.gov>
  8. Organization: Spillman Data Systems
  9. Lines: 55
  10.  
  11. fsfrick@lerc.nasa.gov (David Fricker) writes:
  12. )In <9301060106.AA10395@>, jhidalgo@ecnet.ec (Javier Hidalgo E.) writes:
  13. )> Hi folks, please if someone know a command similary to last
  14. )> command for read from tacacs.wtmp and failedlogin files, because
  15. )> last only read of wtmp, and information is good.
  16. )
  17. )Try 'who <filename>'.  'who' accepts (as an argument) a file to look
  18. )at instead of the default /etc/utmp.  You may want some way to
  19. )reverse the order to look more like 'last', though.
  20. )
  21. )Of course, 'who' doesn't give you all the info that 'last' does, but
  22. )it is a start.
  23.  
  24. Here is a Perl script that reads "utmp" records.  It hasn't been
  25. prettied up.  Currently you pass it a single argument which is the
  26. username whos login/outs you want to see.
  27.  
  28. If you are familiar with Perl this is easy to change to show just
  29. about anything you want.
  30.  
  31. Just change the "64"s and the unpack string to port to a different
  32. machine.  Yes, it's very quick and very dirty.
  33.  
  34. ----- Delete this line and above -----
  35. #!/usr/bin/perl
  36. # Dumps contents of /usr/adm/wtmp in human-readable format
  37.  
  38. eval 'exec perl -S $0 ${1+"$@"}'
  39.     if 0;# not already running under PERL;
  40.  
  41. # /etc/utmp
  42. open( WTMP, "</usr/adm/wtmp" )
  43.  ||  die "Can't read /usr/adm/wtmp: $!\n";
  44.  
  45. @type= split(' ',"MT RLVL BOOT TIME INIT LOGIN USER DEAD ACCT");
  46.  
  47. $oinit= "None";
  48.  
  49. while(  64 == sysread( WTMP, $rec, 64 )  ) {
  50.     ( $user, $init, $line, $type, $pid, $terminate, $exit, $time, $host )=
  51.       unpack( "A8A14A12slssLA16", $rec );
  52.     if(  $ARGV[0] eq $user  ||  "" ne $oinit  &&  $init eq $oinit  ) {
  53.         print $init ? "Init=$init" : "", $user ? " User=$user" : "",
  54.           $line ? " Line=$line" : "", $pid ? " PID=$pid" : "",
  55.           " Type=", $type, $type[$type] ? ":$type[$type]" : "",
  56.           $terminate ? " End=$terminate" : "",
  57.           $exit ? " Exit=$exit" : "", " Time=",
  58.           sprintf("%02.2d:%02.2d:%02.2d %02.2d/%02.2d/%d",
  59.             (localtime($time))[2,1,0,4,3,5]),
  60.           $host ? " Host=$host" : "", "\n";
  61.         $oinit= ( $ARGV[0] eq $user ) ? $init : "";
  62.     }
  63. }
  64. # Line values: "run-level_" "system boot" "old time" "new time"
  65. ----- Delete this line and below -----
  66.