procmail
[Top] [All Lists]

Re: creating directories (was Working Recipe)

2003-07-05 11:31:33
Kreemy observed,

The following works:

:0
* ! LISTNAME ?? ^^^^
{
  NEWDIR=`mkdir -p $MLDIR/$LISTNAME/`

  :0:
  $MLDIR/$LISTNAME/$MONTHFOLDER.$LISTNAME
}

the following does NOT work:

:0:
* ! LISTNAME ?? ^^^^
$MLDIR/$LISTNAME/$MONTHFOLDER.$LISTNAME

It will work if $MLDIR/LISTNAME/ already exists.

I feel stupid doing the NEWDIR assignment to create the directory, but
nothing else seemed to work.  Is this the "right" way to do this, or
what am I missing?

Pretty much nothing. This is a situation where procmail will not automatically create the directory. This way might generate less load, depending on how test operates on your system:

 :0
 # if $LISTNAME is all newlines, that's no good either
 * LISTNAME ?? .
 {
  :0 # create the directory only if it doesn't already exist
  * ! LISTNAME ?? ? test -d $MLDIR/$LISTNAME
  garbage=| mkdir -p $MLDIR/$LISTNAME

  :0:
  $MLDIR/$LISTNAME/$MONTHFOLDER.$LISTNAME
 }

though it seems redundant to me to have $LISTNAME repeated in the filename if it's the name of the directory.

Here's a way that doesn't run test and still runs mkdir only if it is needed:

 :0
 * LISTNAME ?? .
 {
  :0: # try it
  $MLDIR/$LISTNAME/$MONTHFOLDER.$LISTNAME

  :0eW # if it fails, probably we need to mkdir
  garbage=| mkdir -p $MLDIR/$LISTNAME

  :0a: # if mkdir succeeded, store the message now
  $MLDIR/$LISTNAME/$MONTHFOLDER.$LISTNAME

  # If we get here, then there's a different problem, so let's see
  # what the rest of the rcfile can do, or we can just punt:
  # :0:
  # $DEFAULT
 }


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>