Redirect stdin stdout to multiple files

Thread Tools Search this Thread
# 1  
Old 11-25-2009
Redirect stdin stdout to multiple files

i know how to
a) redirect stdout and stderr to one file,
b) and write to two files concurrently with same output using tee command

Now, i want to do both the above together.

I have a script and it should write both stdout and stderr in one file and also write the same content to another file at the same time.

In other words, both files should contain all stdout and stderr and both files
should be identical, and both files should overwrite any existing files > log1.txt 2>&1

In the above command i want to write the exact ouput to log2.txt at the same time

How to do this?

-srinivas yelamanchili
# 2  
Old 11-25-2009
Code: | tee outputfile1 1> outputfile2

you get two identical output files - is that what you mean?
# 3  
Old 11-25-2009
yes jim,
but in your code the stderr is not written to either of the log files
Both the log files should have the stderr too


---------- Post updated at 12:39 PM ---------- Previous update was at 12:17 PM ----------

This seem to be working, however it shows output on the terminal too 2>&1 | tee log1.txt log2.txt

I want all output only to the log files and not any to the terminal or standard output device

# 5  
Old 11-25-2009
Thanks Jim,
this one works too: 2>&1 | tee log1.txt log2.txt > /dev/null

your code is much simpler and precise

However, while in both cases the logs are now good, the exit code returned at the command line is always '0' and not that of the script

If i use: > log1.txt 2>&1
echo $?
displays the true return code of

Now, with the tee command it's lost. How to fix this?

Really appreciate your feedback
# 7  
Old 11-25-2009
Thanks jim

echo ${PIPESTATUS[0]}

shows the exit code of the first command

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
[stdin / stdout] Strategies for redirecting outputs Marmz Shell Programming and Scripting 5 04-10-2017 03:21 PM
How to set font color for STDIN,STDOUT and STDERR? ungalnanban UNIX for Advanced & Expert Users 2 07-28-2011 02:45 AM
STDIN and STDOUT eightball UNIX for Dummies Questions & Answers 1 05-12-2011 11:35 PM
Redirect String to STDIN Panman82 Shell Programming and Scripting 3 02-25-2011 01:29 AM
read and write stdin/stdout in unix MrUser Programming 3 04-21-2010 02:40 PM
Controlling a child's stdin/stdout (not working with scp) DreamWarrior Programming 9 03-17-2010 10:43 AM
Redirecting stdin/stdout to/from command from/to string doc_cypher Shell Programming and Scripting 5 03-15-2010 06:45 PM
can't close stdin/stdout in shell Corona688 Shell Programming and Scripting 10 02-18-2010 07:52 PM
stdout/stdin + flushing buffers JamesGoh Programming 9 10-02-2008 08:15 PM
Wrapper script for image deployment - stdin/stdout - named pipes and the like andreas.ericson Shell Programming and Scripting 2 09-23-2008 03:35 PM
inline redirect stdin ct2marer UNIX for Advanced & Expert Users 2 09-09-2008 09:50 PM
inline redirect stdin ct2marer Shell Programming and Scripting 5 09-09-2008 09:50 AM
Redirect stdin and out to sockets gyula Programming 1 09-02-2008 10:30 AM
C++ How to use pipe() & fork() with stdin and stdout to another program vvaidyan Programming 2 05-16-2008 07:30 PM
redirect STDIN prkfriryce Shell Programming and Scripting 4 01-04-2007 09:11 AM