Thread View: comp.unix.shell
3 messages
3 total messages
Started by There will be enough room in HEA...
Thu, 06 Sep 1990 22:35
Need a shell scrpit!!
Author: There will be enough room in HEA...
Date: Thu, 06 Sep 1990 22:35
Date: Thu, 06 Sep 1990 22:35
11 lines
710 bytes
710 bytes
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. Koffi
Re: Need a shell scrpit!!
Author: 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
List of last logins
Author: 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."
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads