0

いくつかのバイナリ ファイルを無限に実行するシェル スクリプトがあります。私のタスクは、これらのバイナリ ファイルによって表示される出力を、タイムスタンプ (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 に答える