Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exec to file and screen 1

Status
Not open for further replies.

butterfm

Programmer
Feb 15, 2002
132
GB
Hi,

Anyone know how to use exec to direct standard out to a file and also to the screen.

If I do :

exec > $LOGFILE

It goes to logfile but I get nothing to screen,

i've tried

exec > $LOGFILE | tee

But no luck. It's a long script so i'd rather not have to | tee for every echo statement if I can help it.

Any assistance is appreciated.

Thanks,
M
 
Put a wrapper script around it:-
Code:
#!/bin/ksh
/path/to/my/big/script | tee $LOGFILE

On the internet no one knows you're a dog

Columb Healy
 
Or simply do something like this in your actual script:
Code:
...
LOGFILE="/path/to/your/logfile"
[!]([/!]
' your actual long script here, untouched
[!])| tee $LOGFILE[/!]
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If your OS and shell supports command substitution:

Code:
exec > >(tee savedoutput) 2>&1

Another idea I found on another site (login required) which doesn't depend on command substitiution:

Code:
#!/bin/sh

logfile=/tmp/shtee.log
pipe=/tmp/shtee.$$.pipe
mkfifo $pipe

echo starting
exec 3>&1
tee $logfile <$pipe >&3 &
teepid=$!
exec 1>$pipe

echo this is a test to see how well this is working

exec 1<&3 # close pipe
wait $teepid
rm $pipe

echo done

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top