On Thu, Oct 21, 1999 at 08:22:48PM -0600, Les Richardson wrote:
Hi everyone,
I would like to keep a folder of backup mail for all students, identical
to var/spool/mail but in another secure location.(on same server with
limited permissions, etc.) Mail still is delivered to /var/spool/mail as well.
Is there any way to easily filter this by group membership of users. (ie
Grade 7, Grade 8, etc.)
Create a small script which reads /etc/passwd and adds aliases
to /etc/aliases (or where sendmail expects that file; see
newaliases(1)). The aliases should look like this:
login: \login, /some/path/login
That will send mails for "login" to "login" and also store
them in the file /some/path/login. Beware that /some/path/login
*must* be writeable for "login" (basically, if no filters
are installed, sendmail will use "login: /var/spool/mail/login"
as "alias" for "login"). This script should do the trick:
BEGIN {
# Read aliases file and print the part *before*
# the generated aliases
aliases="/etc/aliases";
DELIM="### AUTOMATIC GENERATED ALIASES"
count = 1;
while ((getline < aliases) > 0)
{
if ($0 == DELIM)
{
count --;
if (count < 0)
break;
}
else
print;
}
print DELIM;
}
{
login=$1; gid=$4;
if (gid > 100 && gid < 500)
{
printf ("%s: \\%s, /secure/mails/%s/%s\n", login, login, gid, login);
}
}
END {
print DELIM;
while ((getline < aliases) > 0)
{
print;
}
}
Save this to a file and run it with
awk -F: -f file /etc/passwd
It will print a new version of /etc/aliases to stdout. When that
looks ok, you can redirect stdout to a file and then copy that
to /etc/aliases (it's not a good idea to redirect directly
to /etc/aliases :-)
--
Dipl. Inf. (FH) Aaron "Optimizer" Digulla Tel: +41-1-229 27 18
"(to) optimize: Make a program faster by EMail:
dia(_at_)unix(_dot_)swx(_dot_)ch
improving the algorithms rather than by
buying a faster machine."