[lug] bash -x script_to_debug

D. Stimits stimits at idcomm.com
Sun Apr 1 10:00:18 MDT 2001


rm at mamma.varadinet.de wrote:
> 
> On Sun, Apr 01, 2001 at 03:11:20AM -0600, D. Stimits wrote:
> > Bob Collins wrote:
> > >
> > > Is there a way to capture the output sent to the screen when
> > > running a script like below?
> > >
> > > bash -x script_to_debug
> > >
> > > --
> > >    Regards, Bob Collins
> > > Computers are useless.  They can only give you answers.
> > >                 -- Pablo Picasso
> >
> > The "tee" command is nice for this. For example, if it is just standard
> > out (no standard error):
> > bash -x script_to_debug | tee FileNameToLogTo.txt
> 
> Won't work like that. You'll only catch the output of
> the script, _not_ the debugging messages of bash
> which are sent to stderr (file descriptor 2).
> You have two options:

True, but you can do the same redirect with tee so you can "have your
cake and eat it too". With tee, not only will the log see it, so will
you.

> 
>  - redirect the output of bash
> 
>    bash -x script_to_debug 2>log.txt

bash -x script_to_debug 2>&1 | tee SomeLogFileName.txt

> 
>  - redirect both the output of bash as well
>    as the output of the script (and the error
>    messages of the script)
> 
>    bash -x script_to_debug >log.txt 2>&1
> 
>  - record the whole session with 'script'
> 
>   $ script log.txt
>     Script started, file is log.txt
>   $ bash -x script_to_debug
>   + ....
>     ....
>   $ ^D
>   $ Script done, file is log.txt
> 
>   If you don't give a filename to script it wil save
>   all output to the file 'typescript'. You need to
>   enter Ctr-D to stop script from recording the session.
> 
>  Ralf
> 
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug



More information about the LUG mailing list