title: How to pipe all terminal output including error messages from script to a log file
body: <p>I am trying to make a readable log file for a large backupscript.<br>
  Within the script I simply pipe all output from the commands to a big file which then later can be "cleaned" by the script. For example:</p>
  
  <pre><code>echo "Error occurred" &gt;&gt; log.file
  mount disk &gt;&gt; log.file
  </code></pre>
  
  <p>The warnings and error I have missed I pipe at the console when executing the script.  </p>
  
  <pre><code>backup.script &gt;&gt; log.file
  </code></pre>
  
  <p>But even than, error messages are not always logged in my file, when executing the script (with pipe) by cron I get mails from rsync and script errors:</p>
  
  <pre><code>rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)
  rsync: write failed on "/mnt/backup1/xxxxx": No space left on device (28)
  rsync error: error in file IO (code 11) at receiver.c(322) [receiver=3.0.9]
  rsync: connection unexpectedly closed (215 bytes received so far) [sender]
  rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
  </code></pre>
  
  <p>and when a script error occurs:</p>
  
  <pre><code>/data/scripts/backup.auto: line 320: syntax error near unexpected token `else'
  </code></pre>
  
  <p>How can I include these error messages in my log file?</p>