procmail
[Top] [All Lists]

Re: calling external programs using variable assignment

2006-06-25 23:53:57
On 6/25/06, Don Russell <don(_at_)drussell(_dot_)dnsalias(_dot_)com> wrote:
DUMMY = `( \
    cd ${DELIVERY_DIR} \
    find * -print0 | xargs -0trI {fn} gzip -c \"{fn}\"" > \"{fn}.gz\""; \
    )`

This isn't really a procmail question, it's an xargs question.  The
answer to the xargs question is that xargs does not use a shell to run
the command that is its argument, so you can't use redirection in the
command run by xargs.

I do not know why I need those extra " after \" but it seems to generate
the correct command.

The parse of the xargs command that you've written is
xargs
-0trI
{fn}
gzip
-c
\"{fn}\"" > \"{fn}.gz\""

In this last argument, the third double-quote (the second one after
the second backslash) matches the final double quote, yielding the
substring ( > \"{fn}.gz\") which is concatenated with the previous
substring (\"{fn}\").  The backslashes are then removed, leaving a
finished string ("{fn}" > "{fn}.gz") which forms a single argument to
gzip.  So even if you could use redirection with xargs, which you
can't, you've botched the quoting.

The right way to do this is with a shell loop:

find . -print0 | while read -d $'\0' name; do gzip -c "$name" > "$name".gz; done

If your shell doesn't support the $'\0' syntax for a nul byte or
doesn't have the -d option of read, you'll have to make sure none of
the file names contains a newline character by some other means, and

find . -print | while read name; do gzip -c "$name" > "$name".gz; done

To make this slightly relevant to procmail, I suggest that you do this
with a recipe rather than with a dummy assignment, like so:

LOCKFILE=gzip$LOCKEXT
SAVEDIR=$MAILDIR
MAILDIR=$DELIVERY_DIR
:0
* ! MAILDIR ?? ^^\.^^
* ? find . -print0 | while read -d $'\0' name; do gzip -c "$name" >
"$name".gz; done
{ LOG="gzip was successful
" }
MAILDIR=$SAVEDIR
LOCKFILE

The test of MAILDIR against a single dot is to be sure that the change
of directory to the delivery dir was successful.

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail