Postfix command line output redirection

I created a postfix command in the /etc/postfix/master.cf file with a valid command that outputs the output to STDOUT and STDERR. Everything works fine when called on the terminal (so there is an output to STDOUT and STDERR), but when postfix is ​​enabled, issue the no output command. I wanted to verify this by redirecting STDOUT and STDERR to split the files, for example:

Example command from /etc/postfix/master.cf argv = echo foo → /tmp/test.log

The email was received and redirected to this command correctly, which still says it in mail.log, but the file is not created when postfix receives the email.

Does anyone know why this is happening?

Thanks in advance

+4
source share
1 answer

The pipe (8) documentation explains why this happens:

argv = command ... (required)
             The command to be executed. This should be indicated as the last attribute of the command. The command is executed directly, that is, without interpreting shell metacharacters by the shell command of the translator.

Lack of shell interpretation means that redirection will not work. Instead, >>they /tmp/test.logsimply end as additional arguments for echo.

According to the documentation, Postfix> = 3.0 allows quoting spaces in arguments using "{" and "}", so the following should work:

argv=/bin/sh -c { echo foo >> /tmp/test.log }

, Postfix < 3. ATM - script, , , .

+1