web analytics

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