SUMMARY: redirecting stdout and stderr in a script

From: Dan O'Callaghan <OcallD_at_cogent-dsn.com>
Date: Wed Jul 28 2004 - 05:00:28 EDT
Thanks to all who replied,
It seems that there are a couple of ways to do this,
Ive listed the methods used by Karl Vogel

Two ways to do it just once:

   a.  Have a smaller driver script call the script that's doing all the
       work, redirecting the output as you have above.

   b.  Use a subshell in your script like so:

       #!/bin/sh
       # set the PATH, do your sanity checks, etc.
       ...

       # real work starts here
       (
           command ...

           if test something; then
               command ...
           else
               some other command ...
           fi

           ...

       ) 2>&1 | tee logfile


Thanks
For the help
Dan.


-----Original Message-----
From: Dan O'Callaghan
Sent: Tuesday, July 27, 2004 3:31 PM
To: 'Sunmanagers LIST (sunmanagers@sunmanagers.org)'
Subject: redirecting stdout and stderr in a script

Hi
Ive written a script that basically extracts tar files, copies files and
installs software.

I want to capture the output of stdout and stderr to a log file as well as
viewing it on screen.

Ive worked out that I can use any_command 2>&1 | tee log.file .

Is there anyway that I can do this once globally for the script or do I have
to set it at the end of every command?

Thanks in advance
Dan.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.716 / Virus Database: 472 - Release Date: 7/5/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.716 / Virus Database: 472 - Release Date: 7/5/2004
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Wed Jul 28 05:00:24 2004

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:36 EST