sean@dmr.asa.com (Sean Baker) (05/10/91)
Hello, I'm trying to redirect the output of tar to a file. I can do this fine in the csh by using: tar cvf tarfile /tmp |& tee tar.out But how do I do this with the Bourne shell? I can't seem to get both stdin and stdout sent to the tee program? Any help would be appreciated! Thanks, Sean. ======================================= Sean Baker <sean@dmr.asa.com> Data Management Resources 20725 South Western Avenue, Suite 100 Torrance, CA 90501 USA (213)618-9677
gautier@taclg.af.mil (Sgt Richard Gautier) (05/10/91)
Good luck. I tried to call AT&T about getting the tee program to accept stdin to whatever program it was running. I called them at their software support hotline, and asked them if there was any OTHER way I could do it as well. No luck. What I was trying to do was do a tee sh in every user's .profile so that I could tape their on-line sessions into a file in their $HOME. If you ever find an answer for Sys V 3.2.2, please tell me. Sorry it wasn't an answer, but it is what I have been told (it is supposedly impossible, without the source for tee, I can't check this out, though). +--------------------------------------------+-----------------+ |Richard A. Gautier, Sgt, USAF | _ __ | |HQ TAC/LGSSS Langley AFB, VA 23665 | ' ) ) / | |gautier@wpdis01.af.mil/gautier@taclg.af.mil | /--' o _. /_ | |"Everything I say is a lie....REALLY!" | / \_<_(__/ / | +--------------------------------------------+-----------------+
jik@athena.mit.edu (Jonathan I. Kamens) (05/10/91)
In article <26840@adm.brl.mil>, sean@dmr.asa.com (Sean Baker) writes: |> I'm trying to redirect the output of tar to a file. |> |> I can do this fine in the csh by using: |> |> tar cvf tarfile /tmp |& tee tar.out |> |> But how do I do this with the Bourne shell? I can't seem to |> get both stdin and stdout sent to the tee program? Your question is very confused. If you are asking how to direct both the standard output and the standard error of a command to a file, which is what the "tar" example you gave does, in the bourne shell, then the last bit about "stdin and stdout" does not belong. The answer to the question, in any case, is "tar cvf tarfile 2>&1 | tee tar.out". See the man page for sh. If you are asking how to record both what is typed at a command and what is printed by it as output, then the part of your question about "stdin and stdout" makes sense, but the first part of it does not, because the tar command you gave does NOT do that. In any case, the answer to the question is to use something like "script" which will record a login session. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710
dichter@chdasic.sps.mot.com (Carl Dichter) (05/10/91)
This will work in bourne: $ tar cvf tarfile /tmp 2>&1 | tee tar.out But there is one caveat (and it is really true in any shell): errors will come out immediately and normal output is buffered, therefore it is harder to determine where an error actually occured. Look at the following runs: $ tar cvf $HOME/tarfile $HOME/tardir a /home/libra/carl/tardir/afile 1 blocks a /home/libra/carl/tardir/myfile 2 blocks a /home/libra/carl/tardir/okfile 2 blocks tar: /home/libra/carl/tardir/yourbadfile: Permission denied $ tar cvf $HOME/tarfile $HOME/tardir 2>&1 | tee $HOME/tar.out2 tar: /home/libra/carl/tardir/yourbadfile: Permission denied a /home/libra/carl/tardir/afile 1 blocks a /home/libra/carl/tardir/myfile 2 blocks a /home/libra/carl/tardir/okfile 2 blocks The tee'd version has the message in a misleading place. Have fun. Carl R. Dichter Staff Software Engineer/Scientist Motorola ASIC Division Chandler, AZ 85224
wallace@ynotme.enet.dec.com (Ray Wallace) (05/10/91)
In article <26840@adm.brl.mil>, sean@dmr.asa.com (Sean Baker) writes... >I'm trying to redirect the output of tar to a file. > >I can do this fine in the csh by using: > > tar cvf tarfile /tmp |& tee tar.out First, in csh can't this be done without tee? Like this - tar cvf tarfile /tmp >& tar.out >But how do I do this with the Bourne shell? I can't seem to >get both stdin and stdout sent to the tee program? In sh it is - tar cvf tarfile /tmp > tar.out 2>&1 Either that or (being fairly new to Unix) I missunderstood the question. --- Ray Wallace (INTERNET,UUCP) wallace@oldtmr.enet.dec.com (UUCP) ...!decwrl!oldtmr.enet!wallace (INTERNET) wallace%oldtmr.enet@decwrl.dec.com ---
lewis@tramp.Colorado.EDU (LEWIS WILLIAM M JR) (05/10/91)
In article <26840@adm.brl.mil> sean@dmr.asa.com (Sean Baker) writes: > >Hello, > >I'm trying to redirect the output of tar to a file. > >I can do this fine in the csh by using: > > tar cvf tarfile /tmp |& tee tar.out > >But how do I do this with the Bourne shell? I can't seem to ... Try: { tar cvf tarfile /tmp 2>&1 } | tee tar.out I haven't tried it, but it should work.
gwyn@smoke.brl.mil (Doug Gwyn) (05/11/91)
In article <26841@adm.brl.mil> gautier@taclg.af.mil (Sgt Richard Gautier) writes: >Good luck. I tried to call AT&T about getting the tee program to accept >stdin to whatever program it was running. I called them at their software >support hotline, and asked them if there was any OTHER way I could do it >as well. No luck. > What I was trying to do was do a tee sh in every user's .profile >so that I could tape their on-line sessions into a file in their >$HOME. If you ever find an answer for Sys V 3.2.2, please tell me. > Sorry it wasn't an answer, but it is what I have been told (it is >supposedly impossible, without the source for tee, I can't check this >out, though). I have several problems with what you said; the main one is the whole idea of somebody interfering with user .profiles like that. Anyway, "tee" is the wrong tool to try to use for such purposes, so it's no wonder you haven't find any way to use it for that purpose. If you can find an implementation of "script", it is probably what you want. The original requestor wanted to direct a process's stdout and stderr into a pipe; never mind whether or not "tee" was reading the pipe -- that is irrelevant. It is obvious how to do this: whatever 2>&1 | ...
max@compaq.com (Max Heffler) (05/11/91)
sean@dmr.asa.com (Sean Baker) writes: >I can do this fine in the csh by using: > tar cvf tarfile /tmp |& tee tar.out >But how do I do this with the Bourne shell? I can't seem to >get both stdin and stdout sent to the tee program? tar cvf tarfile /tmp 2>&1 | tee tar.out -- Max Heffler, Senior Software Engineer internet: max@compaq.com Compaq Computer Corporation uucp: ..!uunet!max@compaq.com P.O. Box 692000 - M050701 phone: (713) 378-8366 Houston, Texas 77269-2000 fax: (713) 374-7305
chip@osh3.OSHA.GOV (Chip Yamasaki) (05/11/91)
In <26840@adm.brl.mil> sean@dmr.asa.com (Sean Baker) writes: > tar cvf tarfile /tmp |& tee tar.out >But how do I do this with the Bourne shell? I can't seem to >get both stdin and stdout sent to the tee program? tar cvf tarfile /tmp 2>&1 | tee tar.out -- -- Charles "Chip" Yamasaki chip@oshcomm.osha.gov