Article View: comp.unix.shell
Article #1017Re: Need a shell scrpit!!
From: Larry Wall
Date: Fri, 07 Sep 1990 00:47
Date: Fri, 07 Sep 1990 00:47
38 lines
1920 bytes
1920 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:
: 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@jpl-devvax.jpl.nasa.gov
Technical Details
Message-ID:
<9422@jpl-devvax.JPL.NASA.GOV>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!usc!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwallReferences:
<11722@bsu-cs.bsu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!usc!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.shell,comp.lang.perl,comp.unix.questions Subject: Re: Need a shell scrpit!! Keywords: JUST SHELL.. Message-ID: <9422@jpl-devvax.JPL.NASA.GOV> Date: 7 Sep 90 00:47:55 GMT References: <11722@bsu-cs.bsu.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 38