paranet(_at_)nexus(_dot_)flash(_dot_)net asked,
| Can anyone suggest an easy method using procmail to deliver mail to
| subdirectories of /var/mail based on the first two characters of $LOGNAME.
| For example:
|
| username ($LOGNAME) = abc
| $MAILDIR = /var/mail/a/b
As Philip Guenther has posted, you want ORGMAIL=/var/mail/a/b/abc; you should
not change $MAILDIR. $MAILDIR is preset to $HOME and should be left that way
unless and until the user decides to specify a different directory in his or
her own .procmailrc.
Anyhow, I posted code for something very similar on this list a long time
ago; it should be in the archives somewhere.
| I have tried setting SHELL=/usr/bin/ksh and executing the korn shell
| "typeset" command from within the /etc/procmailrc file to extract the first
| two characters of $LOGNAME. However, procmail skips these lines for some
| reason. I get the following messages when processing /etc/procmailrc:
|
| procmail: Skipped "| typeset -L2 first2alphas=$LOGNAME"
| procmail: Skipped "| typeset -L1 alpha1=$first2alphas"
| procmail: Skipped "| typeset -R1 alpha2=$first2alphas"
FIRST PROBLEM: You didn't tell us how you're trying to code it, but
apparently your procmailrc syntax is wrong to start if procmail is skipping
those lines.
SECOND: there are no characters from $SHELLMETAS in those commands, so if
procmail weren't skipping them it would to execute them itself instead of
invoking a shell. The simple solution to this part is to append a semicolon,
but you'll still have all the other problems I'm listing.
THIRD: as Philip said, it's a lot of overhead to fork ksh three times for
every incoming letter; if your problem is system overload, that will not
help!
FOURTH: you're defining the variables inside child processes, so they will
not be known to procmail anyway.
Here's what you need to put into /etc/procmailrc. Note that it does not call
any outside processes but does it completely inside procmail.
:0
* LOGNAME ?? ^^\/.
{ FIRST=$MATCH }
:0
* LOGNAME ?? ^^.\/.
{ SECOND=$MATCH }
:0E # in case of any single-character lognames, fill with a colon
{ SECOND=: }
ORGMAIL=/var/mail/$FIRST/$SECOND/$LOGNAME
DEFAULT=$ORGMAIL
FIRST SECOND # unset the extra variables
However, it has one flaw: you cannot precompile this value of $ORGMAIL into
the procmail binary, so procmail will always check to make sure that it can
write to the compiled-in value of $ORGMAIL whenever it is invoked without
the -m option. So make sure that the compiled-in value of $ORGMAIL is
something writable (or creatable) and also that, for every user, the new
value of $ORGMAIL is writable (or creatable) and readable (and that all those
/var/mail/?/? directories exist).
If your version of procmail is too old to do extraction, upgrade.