title: Redirecting output of a program to a rotating file
body: <p>I am trying to redirect the output of a <strong>continuously</strong> running program to a file say <code>error_log</code>. </p>
  
  <p>The command I am using looks like this, where <code>myprogram.sh</code> runs continuously generating data and writing to <code>/var/log/httpd/error_log</code></p>
  
  <ul>
  <li><code>myprogram.sh &gt;&gt; /var/log/httpd/error_log</code></li>
  </ul>
  
  <p>Now I am using <code>logrotate</code> to rotate this file per hour. I am using <code>create</code> command in <code>logrotate</code> so that it renames the original file and creates a new one.
  The <code>logrotate</code> config looks like </p>
  
  <pre><code>/var/log/httpd/error_log {
  # copytruncate
   create
   rotate 4
   dateext
   missingok
   ifempty
   .
   .
   .
  }
  </code></pre>
  
  <p>But here redirection fails. What I want is <code>myprogram.sh</code> to write data to <code>error_log</code> file irrespective of it being rotated by logrotate, obviously to newly generated <code>error_log</code> file</p>
  
  <p>Any idea how to make redirection work based on the <strong>file name</strong> and <strong>not</strong> the <strong>descriptor</strong> ?</p>
  
  <p>OR </p>
  
  <p>Any other way of doing it in bash ?</p>