Bernard Fay
2018-04-24 12:37:04 UTC
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,
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,