List of last logins

Joe Smith jms at tardis.Tymnet.COM
Fri Sep 7 12:14:28 AEST 1990


In article <11722 at bsu-cs.bsu.edu> koffi at bsu-cs.bsu.edu (There will be enough room in HEAVENS for all of US) writes:
>Hello Cybersapce,
>I am looking for a shell script that could do the following task:
>	1) Create a file of users (login name followed by the real life name) 
>who haven't logged on the system since the year 1988.

One of our programmers (Ed Mooring) is using this:
(Adjust the "thresh").

#!/usr/local/bin/perl
$ll_t = "LA8A16";
push (@ARGV,'/var/adm/lastlog') if $#ARGV < 1;
while(($name,$pw,$uid, at rest) = getpwent) {
    next if $pw eq "*";
    $uname{$uid}=$name;
    $lasttime{$uid} = -1;
}
foreach (@ARGV) {
    open (LL,$_) || die "open $_ $!";
    $i=0;
    for ($i = 0;read(LL,$foo,28);$i++) {
	next unless $uname{$i};		#skip names not in password file
	($when, $where, $host) = unpack($ll_t,$foo);
	if ($lasttime{$i} <=$when) {
	    # more recent login
	    $lasttime{$i} = $when;
	    $lasthost{$i} = $host;
	    $lastwhere{$i} = $where;
	}
    }
    close(LL);
}
$thresh = time - 90 * 86400;
sub bymag {$a-$b;}
@ids = sort bymag keys(%uname);
foreach (@ids) {
    next if $lasttime{$_} > $thresh;
    if ($lasttime{$_}) {
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lasttime{$_});
	$mon++;
	print "$_($uname{$_}) $mon/$mday/$year $lastwhere{$_} $lasthost{$_}\n" ;
    }
    else {
	print "$_($uname{$_}) never logged in\n";
    }
}
-- 
Joe Smith (408)922-6220 | SMTP: jms at tardis.tymnet.com or jms at gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C41    | BIX: smithjoe | 12 PDP-10s still running! "POPJ P,"
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga speaks for me."



More information about the Comp.unix.shell mailing list