Automatically send stdout and stderror to a file as well as to the screen, but without using tee
Hi,
I've been using the following commands in my automated scripts, to ensure that all text output is sent to a log file instead of to the screen:
However, I've now discovered that the system used for automating the script executions actually saves all screen output to its own log file anyway. It would be useful for me to write all future scripts so that all stdout and stderr text is sent to the screen (to be saved to the automation log) as well as to the $SCRIPT_LOG_FILE specified above.
I'm aware that I could use something like this on each command within my scripts from now on:
...and this would give me the desired result, but it's a bit tedious to have to do that after every command within the script.
I'm also aware that I the scripts could be called with a tee argument:
...and this would also give me the desired result, but I don't want to complicate the automated commands used to call scripts.
Finally, I'm also aware that I could use a 'wrapper script' for each one, and put a command like that above within it, and this would also have the desired effect, but it's a bit of a messy solution and I'd rather not have to double up on the number of script files I need, just to accomplish this.
Apologies if this has already been answered before, but I've searched quite a bit and haven't been able to find exactly what I'm looking for yet.
Thanks for the quick reply. Unfortunately I'm using ksh on Solaris 10 (probably should have mentioned that), it's the standard shell used for all of our scripts. I saw that method and tried it already, but it didn't work under ksh. A pity as it's quite elegant!
I think I might have found something that does work though:
This is basically what that syntax does... Creates a piped background process. This code is good, except I always recommend to quote variable expansions (What if a filename ends up having a space in it?) and avoid all capital variables (What if we accidentally overlook its use as an environment/internal variable).
ie:
This User Gave Thanks to neutronscott For This Post:
Dear all,
redirecting STDOUT & STDERR to file is quite simple, I'm currently using:
Code:
exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.log
But during script execution I would like the output come back again to screen, how to do that?
Thanks
Luc
edit by bakunin: please use CODE-tags like the... (6 Replies)
I have a problem when i try to create a log file from a daemon process using shell scripting in ubuntu 12. Ultimatly what i want to achieve is run a java/jar file from a script. After scourging the internet i found several solutions to do this, the one i choose is to create a startup script that... (4 Replies)
I have code fragment like
{
aa
bb
cc
} > $LOG
aa bb cc, all call function "ff", I want "ff" to print on the screen,but others do not print on the scree, is there a method? I can't use "tee", becasue tee I meet the write "error"
ff()
{
echo "hello"
} (2 Replies)
I have to redirect STDERR messages both to screen and also capture the same in a file but STDOUT only to the same file.
I have searched in this formum for a solution, but something like
srcipt 3>&1 >&2 2>&3 3>&- | tee errs
doesn't work for me...
Has anyone an idea??? (18 Replies)
Dear all,
redirecting STDOUT & STDERR to file is quite simple, I'm currently using:
exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.logBut during script execution I would like the output come back again to screen, how to do that?
Thanks
Lucas (4 Replies)
BACK STORY:
I have a script build.py . (It's for creating the ISO file for a special edition of Swift Linux.) This build.py script executes the mintConstructor.py script that I use to modify the Regular Swift Linux ISO to get the special edition Swift Linux ISO. The lines of the script that... (2 Replies)
Hi All,
I need to redirect screen o/p of shell script to file , but I don't want to use "tee" :Dcommand
./test.sh 2>&1 | tee /var/tmp/testing`date +'%d%h%Y%T'`.log
but I want to write some code inside the shell script itself so wen I execute
./test.sh
it will display o/p in screen... (3 Replies)
Hi,
I would like to process, filter the same ASCII asynchronous live data stream in more than one pipe pipeline.
So the one pipeline should filter out some records using grep key word
and more than one pipes pipelines
each should grep for another key words, each set seperately for each... (5 Replies)
I have been doing this:
make xyz &> xyz.log &; tail -f xyz.log
The problem with this is that you never can ge sure when "make xyz" is done.
How can I pipe both stderr and stdout into tee so both stderr and stdout are copied both to the display and to the log file?
Thanks,
Siegfried (3 Replies)
Hello All,
I have a perl script , and the STDERR and additional FH is redirected to the STDOUT like below:
open STDOUT ,">>$log" or die "$! :: $log\n";
open STDERR ,">&STDOUT" or die "$! :: Can redirect STDERR to STDOUT\n";
select STDERR; $|=1;
open LOG ,">&STDOUT" or die "$! :: Can... (2 Replies)