gpt4 book ai didi

pipe - 重定向后缀命令管道的输出

转载 作者:行者123 更新时间:2023-12-01 05:09:03 25 4
gpt4 key购买 nike

我在/etc/postfix/master.cf 中创建了一个 postfix 命令管道,其中包含一个在 STDOUT 和 STDERR 上产生输出的有效命令。在终端上调用时一切正常(因此在 STDOUT 和 STDERR 上有输出) - 但是当让 postfix 发出命令时,没有显示输出。我想通过将 STDOUT 和 STDERR 重定向到单独的文件来测试这一点,如下所示:

来自/etc/postfix/master.cf 的示例命令
argv=echo foo >>/tmp/test.log

电子邮件被正确接收并重定向到此命令,这就是 mail.log 所说的,但是当 postfix 收到电子邮件时不会创建该文件。

有谁知道为什么会这样?

提前致谢

最佳答案

pipe(8) documentation解释了为什么会发生这种情况:

argv=command... (required)
The command to be executed. This must be specified as the last command attribute. The command is executed directly, i.e. without interpretation of shell meta characters by a shell command interpreter.



shell 没有解释意味着重定向将不起作用。取而代之的是 >>/tmp/test.log最终只是作为 echo 的附加参数.

根据文档 Postfix >= 3.0 允许在带有“{”和“}”的参数中引用空格,因此以下应该有效:
argv=/bin/sh -c { echo foo >> /tmp/test.log }

我仍然需要找到一个适用于 Postfix < 3 的内联解决方案。 ATM 我诉诸于调用一个包装 shell 脚本,反过来设置重定向。

关于pipe - 重定向后缀命令管道的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26403571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com