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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirection in ksh

Status
Not open for further replies.

vlz

IS-IT--Management
Aug 11, 2002
56
IL
Hi,
Could you help me to find out what is wrong in my script?

#!/bin/ksh
exec 3 >> log
{
print start
print -u2 error
print -u3 "only to logfile"
print end
} 2>&1 |tee log

I get on my terminal and in the log file the same:
start
error
end

But I expect to get in the log file:
start
error
only to logfile
end

Thanks in advance,
Vadim
 
I think the problem is that your exec opens the file, then the tee, in another process, opens the file with another file handle. If the >> redirection writes to log, it doesn't make the file pointer for tee advance and a subsequent write by tee overwrites the output. Note that even if there is no write from tee after &3 output, tee will still write the EOF marker where it stops.
 
Is it possible to get log file as I expect?

Thanks,
Vadim
 
Not using an external program like "tee". Did you try redirecting &1 and &2 to the log file?
 
Well, then you wouldn't get your output to the screen... I don't know, maybe you're being too picky. You may have to duplicate your output lines to write once to log and once to std out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top