Shell 如何在两个不同的文件中分离二进制文件的显示输出?

Shell 如何在两个不同的文件中分离二进制文件的显示输出?,shell,unix,Shell,Unix,我有一个Shell脚本,它无限地执行两个二进制文件。我的任务是将这些二进制文件显示的输出重定向到带有时间戳(YY-MM-DD)的日志文件中。这项任务相当容易,但当一天发生变化时,问题就会出现。这就是我的问题——如果一个特定的二进制文件正在执行(尚未完成)并且日期发生了变化,那么输出应该显示在两个不同的文件中,并且具有不同的时间戳。例如: while true; do if (current_date = new_date); then execute bina

我有一个Shell脚本,它无限地执行两个二进制文件。我的任务是将这些二进制文件显示的输出重定向到带有时间戳(YY-MM-DD)的日志文件中。这项任务相当容易,但当一天发生变化时,问题就会出现。这就是我的问题——如果一个特定的二进制文件正在执行(尚未完成)并且日期发生了变化,那么输出应该显示在两个不同的文件中,并且具有不同的时间戳。例如:

    while true; do
      if (current_date = new_date); then
        execute binary >> log.out_$current_date
    // If binary is still in the process of execution how to redirect in 2 files ???
      else 
        execute binary >> log.out_$new_date
      fi
    done
所需输出为::在当前日志文件中记录的当前_日期的文件输出和在新文件中记录的新日期的文件输出
..... 请帮助

只需创建一个进一步的脚本,从二进制文件的
标准输出
读取,并在每一行读取后检查日期

(source of outputdatescript.sh)

#!/bin/bash

while read line; do

    # example made with unix data, replace it with your date string generator
    date=$(date "+%s")

    echo $line >> file.$date

done;
那么主脚本中的命令必须是subst from

execute binary >> log.out_$current_date

execute binary | outputdatescript.sh