【问题标题】:creating a tarball, encrypt it on the fly and keeps tar messages in a log file创建一个 tarball,动态加密它并将 tar 消息保存在日志文件中
【发布时间】:2015-05-14 09:50:25
【问题描述】:

在 OSX 上,我正在尝试创建目录的 tarball 并动态加密 它使用 gpg 并将 tar 消息的输出保存在日志文件中 稍后分析。

虽然 tar+gpg 运行起来很简单

tar zcvf - foo | gpg -e -r foo@bar.com -o foo.tgz.gpg

到目前为止,我没有记录 tar 的输出(可能还有 gpg 的输出) case) 到日志文件中。

我尝试了几种组合

tar | gpg | tee
tar | gpg 2>&1 >(tee)
tar | gpg > file.log

这里有什么帮助吗?

干杯 大卫

【问题讨论】:

    标签: bash shell tar gnupg tee


    【解决方案1】:

    2> file.log 应该实现它。 如果您想tee stderr 流并使其保持到原始目的地,您可以使用

    2> >(tee file.log >&2)

    在你的例子中:

    tar zcvf - foo 2> >(tee file.log >&2) | gpg -e -r foo@bar.com -o foo.tgz.gpg
    

    您的尝试没有成功,因为管道 (|) 仅将上一个命令的 stdout 转发到当前命令的 stdin。当前命令 (gpg) 无权访问上一个命令 (tar) 的 stderrstderr 已经到达目的地(很可能是您的终端)。

    2> >(command ) 管道(字面意思是 >() 在下面创建一个未命名的操作系统级管道)stderrstdincommand。由于command 是一个子进程,它的stderr (#2) 描述符将指向与父进程的stderr 相同的文件。

    【讨论】:

      【解决方案2】:

      问题是当在行尾使用 2> 时,您只重定向第二个命令 (gpg) stderr。如果您想(看起来)重定向 tar 命令 stderr,您应该在管道之前添加 2> 日志文件,如下所示:

      tar zcvf - foo 2> tar.log | gpg -e -r foo@bar.com -o foo.tgz.gpg
      

      【讨论】:

        猜你喜欢
        • 2012-04-27
        • 1970-01-01
        • 1970-01-01
        • 2020-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多