How to write $Log_general to Log1 and Log2 on both time, without printing anything to screen?

remark: Log1 and Log2 files need to update separately from $Log_general, I don't want to copy Log1 to Log2!!

I tried the following but only Log2 got updated

 echo $Log_general 1>Log1 1>Log2


./my_script.sh 1>Log1 1>Log2

and with the following there was the problem that $Log_general output appears on screen while I aim to write only to the files Log1 and Log2:

 echo  $Log_general | tee -a Log1 Log2

You should be able to use the tee command to pipe output first to one file and stdout, and then the stdout to the second file. Something like:

echo $Log_general | tee Log1 > Log2


I didn't see your edit Jennifer before I posted, but the usage above doesn't output to the screen for me (I'm running cygwin though, rather than a Linux terminal - hopefully the output is the same)

  • not good because I dont want to write log1 in to Log2 (Log2 need to update only by the "echo $Log_general" – jennifer Oct 19 '10 at 12:26
  • Sorry, you've lost me. I thought you wanted to log the output of a command (in this example, echo $Log_general) to two files at the same time, which is what my snippet does. – Ash Oct 19 '10 at 12:31
  • @Ash see my last remark (Log1 > Log2 is illegal Log2 need to update only by the echo...) – jennifer Oct 19 '10 at 12:31
  • @jennifer: Have you tried to run the command I gave? – Ash Oct 19 '10 at 12:32
  • 1
    @jennifer: I don't actually understand your comments here, but based on your use of tee -a, I think what you're after is echo $Log_general | tee -a Log1 >>Log2 (so as to append to each of Log1 and Log2, rather than truncating). – Gilles 'SO- stop being evil' Oct 19 '10 at 21:15
./bash.sh | tee -a /path/to/firstfile 

If you are trying to append the output of a bash script file to a single file, then the above code will work.

./bash.sh | tee -a /path/to/firstfile |tee -a /path/to/secondfile

The second bit of code should work to write the same output to two different files. I'm using Xubuntu and it works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.