Article View: comp.unix.shell
Article #1018List of last logins
From: Joe Smith
Date: Fri, 07 Sep 1990 02:14
Date: Fri, 07 Sep 1990 02:14
51 lines
2162 bytes
2162 bytes
In article <11722@bsu-cs.bsu.edu> koffi@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,@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@tardis.tymnet.com or jms@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."
Technical Details
Message-ID:
<1214@tardis.Tymnet.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!olivea!tymix!tardis!jmsReferences:
<11722@bsu-cs.bsu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!olivea!tymix!tardis!jms From: jms@tardis.Tymnet.COM (Joe Smith) Newsgroups: comp.unix.shell,comp.lang.perl,comp.unix.questions Subject: List of last logins Message-ID: <1214@tardis.Tymnet.COM> Date: 7 Sep 90 02:14:28 GMT References: <11722@bsu-cs.bsu.edu> Reply-To: jms@tardis.Tymnet.COM (Joe Smith) Organization: BT Tymnet, San Jose, CA Lines: 51