Need a shell scrpit!!

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Fri Sep 7 10:47:55 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:
: 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.

Mmm.  Since it's cross-posted to comp.lang.perl, I presume a solution in
Perl would be acceptable.  This one works on my machines.  As you can see,
there's a lot of other information that you could print out too.

#!/usr/bin/perl

$lastlog_t = "L a8 a16";		# Your struct lastlog may differ

$LEN = length(pack($lastlog_t, 0, '',''));

open(LASTLOG, "/usr/adm/lastlog");
while (($login, $pass, $uid, $gid, $j, $j, $gcos) = getpwent) {
    seek(LASTLOG, $uid * $LEN, 0);
    read(LASTLOG, $lastlog, $LEN);
    ($time, $line, $host) = unpack($lastlog_t, $lastlog);
    ($sec,$min,$hour,$mday,$mon,$year) = localtime($time);
    if ($year <= 88) {
	($fullname) = split(/,/,$gcos);		# BSDism here
	print "$login	$fullname\n";
    }
}

It can probably also be done on some machines with

finger -s -m `awk -F: '{print $1}' /etc/passwd` | \
sed -n -e '/:..>/d' -e '/1990>/d' -e '/1989>/d' -e '/>/p'

but that takes about 30 seconds on my machine.  The Perl script takes about
2 seconds.

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.questions mailing list