Mailing List Archive

Perl script for /etc/alias
Hey everyone, I mentioned that I had a quick and dirty perl script for
taking /etc/alias and making .qmail files from it in the alias dir. Well,
here it is :-) Note the following things...

I have run it only on a RedHat linux system. I only have access to linux
and OpenStep, so if it doesn't work on your XYZ system, you may have to
edit it yourself.

This script ONLY works for this type of line:

user@domain.something: alias@something.something

Thus, remove all "include" lines or "foward" or any other bizarre stuff
in your /etc/aliases file before running it. Also, take the advice I give
in the script and do the following:

cp /etc/aliases .
mkdir ./aliasdir
chmod +x ./etcalias2qmail.pl
./etcalias2qmail.pl

This will put all the .qmail files in the directory ./aliasdir and you can
check them out to make sure everything went alright. Then simply edit the
script to use /etc/aliases and /var/qmail/alias, and run it again as root.

Lastly, I've provided a LOT of scripts to the Internet community for
various things, and heard little back. If this works for you, and it
makes you happy, do me a favor and drop me a line....with that said, enjoy
:)

-------------------------------------------------------------------------
CUT HERE - CUT HERE - CUT HERE
-------------------------------------------------------------------------

#!/usr/bin/perl

# Written by Jeff Carneal (jeff@apex.net)

# This program will take an /etc/aliases file and make .qmail files
# from the information therein

# Here is your aliases file. I recommend copying /etc/aliases
# to ./aliases and leaving this alone

$aliasfile = "./aliases";

# Here is where your qmail alias directory is
# The default is below...
# Again, you might consider setting this to /tmp or something,
# running the program, and making sure nothing goes to hell on you

$qmail_alias_dir = "./aliasdir";


# Shouldn't need to modify anything after this (but who knows)
# ---------------------------------------------------------------

open(ALIAS, $aliasfile) || die "can't open $alias\n";
while(<ALIAS>) {
chop;
s/\t//g;
s/\s//g;
($alias, $address) = split(/:/);

# Strip away the domain name (we should know it anyway)
if($alias =~ /(.*)\@/);
$alias = $1;
}
$real_alias{$alias} = $address;
}
close(ALIAS);

foreach $alias (keys %real_alias) {
print "$alias: $real_alias{$alias}\n";
system("/bin/echo '&$real_alias{$alias}' >
$qmail_alias_dir/.qmail-$alias");
chmod(0644, "$qmail_alias_dir,.qmail-$alias");
}

-------------------------------------------------------------------------
CUT HERE - CUT HERE - CUT HERE
-------------------------------------------------------------------------


'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
`' Jeff Carneal / Sys Admin \ Apex Internet `'
`' jeff@apex.net http://www.apex.net `'
`' The opinions expressed above aren't really mine. They belong to `'
`' someone else who also refuses to take responsibility for them. `'
'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'