Redirect script output to the log

If the whole output of the complex script should be redirected to the log, the following trick could be used.


if [ "$1" != "-log" ] ; then
$0 -log "$@" 2>&1 | tee the_log_file.$$.log
echo "The log file for the current session: the_log_file.$$.log"
exit 0
fi
shift # remove "-log" parameter

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.