title: Tailing Rolling Files
body: <p>I have a directory full of rolling log files that I would like to be able to use tail on.</p>
  
  <p>The files are named as such:</p>
  
  <pre><code>name      modified
  00A.txt   Dec 27 19:00
  00B.txt   Dec 27 19:01
  00C.txt   Dec 27 19:02
  00D.txt   Dec 27 19:03
  </code></pre>
  
  <p>On an older unix system, I'm trying to come up with a shell script that will tail the most recently modified file in a specific directory, and if that file gets administratively closed (rolls to the next file) I want the program to automatically begin tailing the new file without me having to break out of tail to rerun. </p>
  
  <pre><code>tail -100f `ls -t | head -1` 
  </code></pre>
  
  <p>The desired behavior, given the filenames above, would go like this:</p>
  
  <pre><code>./logtailer.sh
  </code></pre>
  
  <p>Then the script would begin tailing 00D.txt.  As soon as the logger was finished writing to 00D.txt and the newest log file was now named 00E.txt, the program would automatically begin tailing that file.</p>
  
  <p>One could write this script by watching the output of tail for the text "File Administratively Closed" and then having the following command run again.</p>
  
  <pre><code>tail -100f `ls -t | head -1`
  </code></pre>
  
  <p>Is there a more elegant way to do this than by watching for the text "file administratively closed"?  How can I even read the output of tail line by line in a shell script?</p>
  
  <p>Edit: I should explain that the -F flag for tail is not an option for me on this system.  It uses a different version of tail that does not contain this feature. 
  OS version - Solaris 10</p>