exec command

How can I use the exec command to log my korn shell session to the screen and the log file?

Currently I have this command:

$exec 1> ${LOG} 2>&1

This logs the output to the log file only. I want it to go to the screen also. Is this possible with this command?

thanks.

Have a look at the script command. Otherwise, you can start the shell with stdout piped into tee. To my knowledge, you cannot use exec to split one stream into two.

Regards,
Alister.

(
  ksh -s
) | tee logfile

Alister,

Is there a way to send stdout to the screen and to a log file?

thanks.

The script I posted will definitely send stdout to both the screen and a log file. Did you test it ?
Also, did you evaluate the script command capabilities as Alister suggested ?

Yes. I did look at the script command. Thanks.

I am trying to get away from the Korn Shell and the TEE command

#!/bin/ksh

command | tee -a $LOG

I thought there was a more elegant way to split the output.

thanks.

This is confusing. Do you want to log your (interactive login) korn shell session or some particular commands in a shell script ?

What is inelegant with ksh and/or tee ?

With the exec command it is issued just once at the top of the script and everything goes to the log, i.e.

$exec 1> ${LOG} 2>&1

With the tee command it has is be issued after every command, i.e.

cmd | tee -a $LOG

cmd | tee -a $LOG

.. and so on

This is incorrect. You certainly can wrap your whole script and "tee" its outputs to have both of them on the screen and a file.

Really. ok. I will give that a try.

Thanks!

(
  cmd1
  cmd2
  ...
  cmdn
)  2>&1 | tee -a $LOG