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                                                      
shift  # remove "-log" parameter

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>




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


A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.