Using tee to create a log

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin Buettner
Date:  
Subject: Using tee to create a log
On Jul 26, 1:03pm, Gorman, John wrote:

> Here is an example: telnet hostname | tee hostname.log
>
> What this does is telnet to host hostname and record the commands
> and output from that into the currenct directory as the filename
> hostname.log.
>
> By the way, this is an excellent way to record your testing history,
> or save your actions for someone who wants to follow what you did at
> a later time.


The problem with using tee for this purpose is that stdout is no
longer connected to a tty (or even a pseudo-tty). This means that
some programs will behave quite differently than they would have had
you not thrown the pipe in.

A better way to capture this kind of output is to use ``script''...

    ocotillo:kev$ script
    Script started, file is typescript
    ocotillo:kev$ echo foo
    foo
    ocotillo:kev$ exit
    exit
    Script done, file is typescript
    ocotillo:kev$ cat typescript 
    Script started on Thu Jul 26 13:27:14 2001
    ocotillo:kev$ echo foo
    foo
    ocotillo:kev$ exit
    exit


    Script done on Thu Jul 26 13:27:24 2001


An example of a program that behaves differently when it's connected
to a terminal vs a pipe is ``ls''. Try doing just ``ls'' and then
``ls | cat'' (or even ``ls | tee''). You'll find that that the former
gives you a listing with multiple columns while the latter gives you
a listing with a single column.

Kevin