-3

I am trying to store stdout&stderr into $log and $script_log. $log has all other process log so used >> $script_log needs only log from set_flag.sh and update.sh.

set_flag.sh 2>&1 >> $log | tee -a $log > $script_log 
update.sh 2>&1 >> $log | tee -a $log >> $script_log

$log is fine. I can see all process logs from both set_flag.sh and update.sh but somehow $script_log has log from set_flag but partial log from update.sh. Not sure why....

Can anybody explain and help me out?

Thanks,

soworl
  • 5
  • 2
  • why write to $log at all? why not just `script | tee > $script_log`? tee already does the splitting for you. there's no need to cache to a file, have tee read from that file, only to write out to ANOTHER file. – Marc B Jul 29 '16 at 18:08
  • @MarcB `tee` reads from stdin, and all passed file parameters are output files. – Siguza Jul 29 '16 at 18:09
  • 1
    That said, I don't get how `tee` can receive any input at all, given that input redirection is done prior to piping. – Siguza Jul 29 '16 at 18:12
  • @Siguza `script 2>&1 >> log` is not the same as `script >> log 2>&1` – Roman Jul 29 '16 at 19:14

2 Answers2

1

Does this do what you want?

set_flag.sh 2>&1 | tee    $script_log >>$log
update.sh   2>&1 | tee -a $script_log >>$log

$log was present in your command twice, and that is probably not needed for the question you posted (all stdout+stderr into $log, and only stdout+stderr of set_flag.sh and update.sh in $script_log).

vapace
  • 340
  • 3
  • 9
  • This is what I was thinking piping stderr and stdout to `tee` and letting that handle the splitting to log and script_log. – JNevill Jul 29 '16 at 19:22
0

I believe you want stdout & stderr of set_flag.sh and update.sh into $log and $script_log.

If that is the case, redirect script outputs to $log and create a symlink with name $script_log and make that point to your $log.

This way, you can save diskspace [no duplicate files] and keep $log and $script_log exactly same.

Community
  • 1
  • 1
Robert Ranjan
  • 1,538
  • 3
  • 19
  • 17