SUMMARY: redirecting stdout and stderr in a script

2007-12-25 3:45:00

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 (codeprof at codeprof.com)'
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

Comments

Got something to say?

You must be logged in to post a comment.