2013-04-10 35 views
0

我有一個shell腳本無限地執行一些二進制文件。我的任務是將這些二進制文件顯示的輸出重定向到帶有時間戳記的日誌文件(YY-MM-DD)。這項任務非常簡單,但是當日子發生變化時會出現問題。這是我的問題 - 如果一個特定的二進制文件正在執行(尚未完成)和日期更改過程中,應顯示的輸出應記錄在具有不同時間戳的2個不同文件中。對於如: -如何隔離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文件的輸出在新文件 要記錄.....請幫助

回答

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

execute binary >> log.out_$current_date 

execute binary | outputdatescript.sh 
相關問題