[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Redirecting all output of a script to a log file
From: |
Bernard Fay |
Subject: |
[Help-bash] Redirecting all output of a script to a log file |
Date: |
Tue, 24 Apr 2018 08:37:04 -0400 |
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,
- [Help-bash] Redirecting all output of a script to a log file,
Bernard Fay <=