Thanks.
Here is what I have come up with: we received a request to add 250
new users to our system, given a full name, and assorted GECOS info.
That file was massages via vi to look like this:
ALEXANDER, CHARLES R.:ADD18:703 681-2320
YOUNG, DOUG:ADD5R:910 432-6105
ZEMAN, LINDA L.:ADD7Z:608 388-4662
The existing /etc/passwd file was analysed, extracting the usernames
and full names from the GECOS field, as this:
abrennan:Ambrose W. Brennan
abrisbon:alan brisbon
zellmanr:Robert A. Zellman
ztollj:Judith L. Lotz
Using the following Perl script, we created usernames for all of the
new users and compared that to the existing user list:
---cut---
#!/usr/local/bin/perl
open(NAMES,"names");
while (<NAMES>) {
chop;
($b_user,$b_fullname) = split(':',$_);
$names{$b_user} = 2;
$fullname{$b_user} = "\L$b_fullname";
}
close(NAMES);
open(ARMY,"army.dorks");
open(DUPL,">duplicates");
open(CONFLICT,">conflict");
while (<ARMY>) {
($fullname, $code, $phone) = split(':',$_);
($lname, $fname, $mi) = split(' ',$fullname);
chop $lname;
$username = substr($fname,0,1) . substr($lname,0,7);
$username = substr($username,0,8);
$username = "\L$username";
$names{$username}++;
$firstname{$username} = "\L$fname";
$dorkname{$username} = "\L$fullname";
#printf("%s %s %s -- %s\n",$fname,$mi,$lname,$username);
}
foreach $name (sort keys(%names)) {
if ($names{$name} == 3) {
if (index($fullname{$name},$firstname{$name}) < 0 ) {
printf(CONFLICT "%s: %s vs %s\n",$name,$fullname{$name},$dorkname{$name});
} else {
printf(DUPL "%s has Burns account %s\n",$dorkname{$name},$name);
}
}
}
close(DUPL);
close(CONFLICT);
---cut---
It (currently) produces two reports: one listing users that already have
accounts, and one that lists new users whose generated usernames are in
use by others. Removing the commented line will cause the generated
usernames to be spilled out to stdout. Enjoy!
--
Les Peters (lpe...@scratchy.hq.af.mil)
GCV 2.1 GCS d(++) H- s+:+ !g p? au+ a27 w+>++ v-- C++ UBASHV++++$
P++ L- 3+ E--- N++ K- W M- V-- po- Y+ t++(+++) 5
j++ R G? tv+ b+++ !D B- e+>+++ u+ h---- f+ r+++ n----(+) y+++(*)