0

我有一个无限执行几个二进制文件的 Shell 脚本。我的任务是将这些二进制文件显示的输出重定向到带有时间戳(YY-MM-DD)的日志文件中。这个任务很简单,但是当一天改变时就会出现问题。这是我的问题——如果一个特定的二进制文件正在执行过程中(尚未完成)并且日期发生变化,则应显示的输出应记录在具有不同时间戳的 2 个不同文件中。例如:-

    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

必需的输出是 :: current_date 的文件输出要记录在当前日志文件中,并且文件在新日期的输出要记录在新文件中.....请帮助

4

1 回答 1

0

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

(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
于 2013-04-10T09:49:30.633 回答