# Prcoessing outoput from tail

**URL:** <https://www.ruby-forum.com/t/prcoessing-outoput-from-tail/90011>\
**Category:** Ruby\
**Created:** [March 24, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/prcoessing-outoput-from-tail/90011 "2007-03-24T23:31:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [March 24, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/prcoessing-outoput-from-tail/90011/1 "2007-03-24T23:31:04Z")

</div>

Hello,

I am trying to figure out how to perpetually process the output from a  
file. That is I continuously want to process output that is appended to  
a file and that file could get rolled out at any time. I use popen  
w/tail, but this opens the file each time and I have to reprocess all  
the files content. Is there a better way to do this or a library that  
would help me? I know that I could probably open the file, tack  
location, and watch the inode to make sure the file has not been rolled,  
but that amounted to a lot of mistakes and I could never get it work  
properly.

Thanks for the help!  
Phy

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [March 24, 2007, 11:42pm UTC](https://www.ruby-forum.com/t/prcoessing-outoput-from-tail/90011/2 "2007-03-24T23:42:06Z")

</div>

Phy P. wrote:

> * * *
> 
> Now that’s room service! Choose from over 150,000 hotels  
> in 45,000 destinations on Yahoo! Travel to find your fit.  
> [http://farechase.yahoo.com/promo-generic-14795097](http://farechase.yahoo.com/promo-generic-14795097)

Check out the file-tail gem:

[http://file-tail.rubyforge.org/](http://file-tail.rubyforge.org/)

Cheery-o,  
Gustav P.

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [March 25, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/prcoessing-outoput-from-tail/90011/3 "2007-03-25T15:00:11Z")

</div>

On Sun, Mar 25, 2007 at 07:30:33AM +0900, Phy P. wrote:

> I am trying to figure out how to perpetually process the output from a  
> file. That is I continuously want to process output that is appended to a  
> file and that file could get rolled out at any time.

I guess this is a follow-on to this thread:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/240367](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/240367)

Have a look at using “tail -F=” or “tail -f=  
–retry”  
within popen.

Screen 1:  
$ tail -F /tmp/foo  
tail: cannot open `/tmp/foo’ for reading: No such file or directory

Screen 2:  
$ echo “abc” \>/tmp/foo; sleep 3; mv /tmp/foo /tmp/foo2; echo “def”

> /tmp/foo

Now Screen 1 shows:

tail: `/tmp/foo' has appeared; following end of new file abc tail: `/tmp/foo’ has been replaced; following end of new file  
def

(read ‘man tail’ for more details. The above example is using tail 5.93  
from  
GNU coreutils, which comes with Ubuntu Linux 6.06)

> I know that I could probably open the file, tack location, and watch  
> the inode to make sure the file has not been rolled, but that amounted to  
> a lot of mistakes and I could never get it work properly.

Let ‘tail -F=’ do that for you 🙂

Brian.
