Dynamically redirect output to duplicate files ???

Hi

There are many posts in this forum regarding reditecting output, but mine is a different problem, please have a look.

My shell script is redirecting output to a log file dynamically. That is it is using -
exec > log1.txt 2>&1
Hence all the traces are appearing in the log1.txt.

I want to redirect the same output to another file log2.txt which will contain the same thing that log1.txt is holding. I have tried in many different ways but nothing is working. "tee" isn't working here like -
exec > log1.txt 2>&1 | tee -a log2.txt

Can you please help me regarding this, I am totally clueless.

Thanks
Nirmalya Sinha

try this, cmd 2>&1 | tee -a log1.txt >> log2.txt

Hi timontt

Thank you sooooo much for the reply. Your script is working fine, but in that case I have to append every command to be executed with "2>&1 | tee -a log1.txt >> log2.txt". But in my case the flow of scripts is huge, it jumps from this script and that, many commands are being executed. So to append that stuff everywhere is just next to impossible. When I am writing "exec > log1.txt 2>&1" in the parent shell, all the traces for all the child shells are appearing in the log1.txt and I wanted to duplicate that.

Actually when I am writing "exec > log1.txt", the "stdin" is permanently redirected to log1.txt for the lifetime of the parent shell and hence I can't redirect the output to somewhere else. So I can't solve the issue in that "exec" way. Anyway I could able to solve the problem in other way with other logic.

Thanks again ...

Nirmalya

With zsh:

zsh 4.3.4% { print $ZSH_VERSION;x;} >log1 >log2 2>&1
zsh 4.3.4% cat log1
4.3.4
zsh: command not found: x
zsh 4.3.4% cat log2
4.3.4
zsh: command not found: x
zsh 4.3.4%