Answer the question
In order to leave comments, you need to log in
Bash script output to screen and log?
What is the _correct_ way to make the output of the bash script launched by ruakmi to the screen and to the log file? I do it in my own way (I will describe below), but which way is kosher?
A piece of code how I do it now:
slog=/yyy/zzz/xxx.log
function main
{
echo "code here"
}
main 2>&1 | tee -a $slog
Answer the question
In order to leave comments, you need to log in
Here is a more interesting option for you. Put the following file somewhere, for example in /etc/functions/teebash:
if [ "s"${TBASHLOG__} = "s" ] ; then
TBASHLOG__="/tmp/tbash.log"
fi
if [ ! ${TEEBASH__} ] ; then
TEEBASH__=1
. $0 "[email protected]" | tee -a ${TBASHLOG__}
exit $?
fi
. /etc/functions/teebash
#!/bin/sh
#TBASHLOG__=/tmp/tbash2.log
. /etc/functions/teebash
echo `date` Is teebash working fine?
If I understand you correctly, then:
tee is a command that displays, or redirects, the output of the command and copies it to a file or variable.
Bodik , you have a normal way if you need to do this one-time in one script. If there are many such scripts, then I would suggest making an additional /bin/bashtee script , for example:
#!/bin/sh
. "[email protected]" | tee -a /var/lob/bashtee.log
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question