Article 4874 of comp.lang.perl: Xref: feenix.metronet.com comp.mail.misc:2958 comp.mail.elm:2708 comp.mail.headers:219 comp.mail.mh:891 comp.mail.sendmail:2049 comp.lang.perl:4874 comp.os.linux:35157 comp.os.minix:1611 comp.unix.misc:3311 comp.unix.admin:4661 comp.unix.shell:3478 Newsgroups: comp.mail.misc,comp.mail.elm,comp.mail.headers,comp.mail.mh,comp.mail.sendmail,comp.lang.perl,comp.os.linux,comp.os.minix,comp.unix.misc,comp.unix.admin,comp.unix.shell Path: feenix.metronet.com!news.utdallas.edu!convex!convex!darwin.sura.net!spool.mu.edu!agate!boulder!wraeththu.cs.colorado.edu!tchrist From: Tom Christiansen Subject: Re: Conversion /etc/passwd --> /usrc/lib/aliases ? Message-ID: <1993Aug10.101001.28845@colorado.edu> Followup-To: comp.lang.perl Originator: tchrist@wraeththu.cs.colorado.edu Sender: news@colorado.edu (The Daily Planet) Nntp-Posting-Host: wraeththu.cs.colorado.edu Reply-To: tchrist@cs.colorado.edu (Tom Christiansen) Organization: University of Colorado, Boulder References: <247i8p$7gi@rwa.urc.tue.nl> Date: Tue, 10 Aug 1993 10:10:01 GMT Lines: 82 [Note followup-to, which may or may not be appropriate.] From the keyboard of tgcpwd@rwa.urc.tue.nl (Wim van Dorst/Prof. Penninger): :I know there is a nifty little program (shell/perl script?) that turns the :Personal Name information in the /etc/passwd file into /usr/lib/aliases :entries for mail programs. This will greatly enhance mail addressing :for the particular machine. : :E.g. the line from /etc/passwd : : duck:2QaBd4:321:20:Harold Wilberforce Clifton:/home/duck:/bin/sh : :would become the entries in /usr/lib/aliases for : : clifton: duck : harold: duck : harold.clifton: duck : harold.wilberforce.clifton: duck : h.clifton: duck : h.w.clifton: duck : harold.w.clifton: duck : etc. : :Thus instead of only being able to do 'duck@what.ever', one can :address this same person with the more comprehensible, and thus more :memorizable, 'harold.w.clifton@what.ever'. : :Where can I find the program that does this? I thought it might be in :the Elm 2.4.22 distribution, in Smail 3.1.28, or in Perl 4.036, but it :seems it is not. Then where _is_ it? Or could a person, knowledgeable :in the field of probably Perl, do up such a script for me, please? Well, that's a pretty easy script to write, but what are you going to do about conflicts? Lots of people have the same first name? Here's a brute force method that pretty much works: #!/usr/bin/perl while (@pw = getpwent()) { ($login, $gcos) = @pw[0,6]; $gcos =~ s/,.*//; # phone information $gcos =~ s/&/\u\L$login/g; # the dreaded & hack $gcos =~ s/\.//g; # can't add too many dots @names = split(' ', $gcos); next unless @names > 0; &alias($names[0]); next unless @names > 1; &alias($names[$#names]); &alias(join ('.', $names[0], $names[$#names])); &alias(join ('.', substr($names[0],0,1), $names[$#names])); next unless @names > 2; &alias(join ('.', @names)); &alias(join ('.', $names[0], substr($names[1],0,1), $names[$#names])) if length($names[1]) > 1; &alias(join ('.', substr($names[0],0,1), substr($names[1],0,1), $names[$#names])) if length($names[1]) > 1 && length($names[2]) > 1; } sub alias { local($alias) = "\L$_[0]"; return if $alias eq $login; if ($seen{$alias}) { warn "$alias already aliased to $seen{$alias}\n"; } else { $seen{$alias} = $login; } print "$alias: $login\n"; } .