LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 07-28-2005, 11:52 PM   #1
Aeiri
Member
 
Registered: Feb 2004
Posts: 307

Rep: Reputation: 30
Weird tail + grep bug


I just found a weird bug in the way tail and grep work together. I've tested this on Slackware -current and Fedora Core 2. Run this code in your terminal:

Code:
$ echo bob jones > bob
$ tail -n 1 | grep bob | grep bob
bob jones
$ tail -fn 1 | grep bob
bob jones
<CTRL+C>
$ tail -fn 1 | grep bob | grep bob
<CTRL+C>
The last command outputs NOTHING!. This should output "bob jones" like the others, what is going on?

I just noticed this while tailing my syslog file, watching iptables' output.

I know this used to work, so when did this all of a sudden happen?

This only happens with the "-f" option, and two piped greps to it. (Note: the -n 1 isn't really needed)
 
Old 07-29-2005, 03:09 AM   #2
rhoekstra
Member
 
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 360

Rep: Reputation: 41
you forgot the filename 'bob' on the tail command line, but okay..

Further, the tail -f tries to follow on a file and passes information in chunks to the grep, and grep does the same ..

To my knowledge, if you put some more lines in 'bob' you WOULD see something, but perhaps not EVERYTHING. the content is stuck in some buffer held to be processed once more info is getting into the file bob while tail is being watching it.

I am not an expert on the way tail and grep work, but I'd say it isn't a bug, but rather you're experiencing the buffered output each program has..
 
Old 12-15-2006, 06:30 AM   #3
rebuke
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Rep: Reputation: 0
I hit a similar problem, a mate managed to solve it, you need to add --line-buffered to any grep thats piping to another, so in your example (with the filename added in):

tail -fn 1 bob | grep --line-buffered bob | grep bob

I realise this is an old post, so sorry for resurrecting it, but just in case other people find it like I did with google, thought it might help...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto tail -f /var/log/messages | grep isdninfo Mopp Programming 4 07-22-2011 11:00 AM
Weird installer bug? MaTrIx709 Debian 2 07-15-2005 04:06 PM
Help pls!!! grep or tail->restart poj Linux - Software 3 11-26-2004 01:50 AM
Amusing/Weird KDE 3.3 bug or error paradoxdruid Linux - Software 15 02-18-2004 11:43 PM
Weird Konqueror problem (a bug?) ivanatora Linux - Software 1 10-13-2003 04:02 PM


All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration