Discussion:
[Help-bash] Redirecting all output of a script to a log file
Bernard Fay
2018-04-24 12:37:04 UTC
Permalink
Hello,

I try to have all output of a script send to a log file as well as to the
screen. I do not want to use "scriptname | tee logfile".

Taking a look at the man page of exec, I thought I could do something like
the following sample script:


#!/bin/bash

exec 4<&1 # Make file descriptor 4 a copy of file descriptor 1
exec 5<&2 # Make file descriptor 5 a copy of file descriptor 2
exec 4>${0}.log 5>&4

echo running the script $0
ls -l
echo bye



The logfile ${0}.log is created but empty.

Do I miss something or I am on the wrong track? Is it feasible the way I
think about it?

Thanks,
Greg Wooledge
2018-04-24 13:06:07 UTC
Permalink
Post by Bernard Fay
I try to have all output of a script send to a log file as well as to the
screen. I do not want to use "scriptname | tee logfile".
https://mywiki.wooledge.org/BashFAQ/106

Loading...