removing tee

Hi,

I have a script where i want to log in details to the standard output as well as log file so that its easy for tracing purposes.

I have used the "tee"command.

The problem with this is my scripts lines are getting longer as for each line i have

#!/bin/ksh
echo "hello world" | tee -a $log
echo "moving file' | teel -a $log
mv file1 fiel2
 

like this my code is more than 300 lines is there a way to get rid of tee at each line and still gets tracing and detailed logs.

Appreciate help

If you like to log the details to the log file as well as display it in o/p, then you should use tee command. If you just need to redirect it to a file, then use the >> redirect operator.

If you think it is too cumbersome to type it in every line of the script, then open vi and then take it to the command mode and then

:1,$s/$/ \| tee -a \$logfile/g

the above command should be able to put the tee for you.

cheers,
Devaraj Takhellambam

devtakh

I can do this, but if someone views my code it looks like so many tee.
I dont want to append tee when i am using sed or awk for processing; only when i am echoing.
i thought there might be a way where i can take output of each function and output it on screen as well as in log file, without using tee at each line.

You could do this: at the beginning of your script, put

tail -f $logfile &

(make sure it's empty first). Save the PID ($!), run your usual script with stdout redirected to the logfile (either by line or by exec 1>$logfile). At the end of your script, kill the tail (you saved the PID, didn't you?)

Ah, I see what you mean. The best I can think of is to create a function and then use that function everytime when you need to log the o/p

echoen()
 {
 echo "$*" | tee -a logilfe
 }

Then in your script use the function instead of the keyword echo instead

echoen "My Name is Don"

cheers,
Devaraj Takhellambam