Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need help about the following

how to write $Log_general to Log1 and Log2 on both time (Without screen printing !)

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

I try the following but only Log2 was update

 echo $Log_general 1>Log1 1>Log2

or

./my_script.sh 1>Log1 1>Log2

or

the problem with the follwiong was that $Log_general output appears on screen
And I my target is to write only to the files: Log1 Log2


 echo  $Log_general | tee -a Log1 Log2
share|improve this question

2 Answers

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

Edit:

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)

share|improve this answer
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 Oct 19 '10 at 21:15
show 4 more comments
./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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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