The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tail, grep and cut sylaan Shell Programming and Scripting 7 03-03-2008 11:41 PM
Badly placed ()'s. - error amitrajvarma Shell Programming and Scripting 3 10-12-2007 01:40 AM
Help with tail /grep needed Felix2511 UNIX for Dummies Questions & Answers 4 05-17-2007 12:22 PM
Constantly updating log files (tail -f? grep? awk?) nortonloaf UNIX for Dummies Questions & Answers 0 12-03-2006 08:20 PM
New to it all, But i wanna script really badly!!! TheNewGuy Shell Programming and Scripting 3 07-03-2004 07:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-22-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
tail | grep lagging badly

I'm trying to use tail/grep to monitor a log file. The command I cooked up is:

tail -n 50 -f output.log | grep 'type:system' | cut -f 5-

A sample line from the log file is:

1208894862 type:system session:0 severity:4 load started

the columns are tab delimited.

this works ok, except that it's inexplicably lagging badly. If I have 2 terminals open, one simply tailing the file and the other tail|greping the file as specified above, it might take 30 seconds or more for the tail|grep terminal to display the next line while the tail terminal displays it instantly.

EDIT: forgot to add this.
Also, sometimes new text does not appear until even more txt is added to the log file.
Example:
'test 1' is written to the log
tail will show this right away, tail | grep will NOT
'test 2' is written to the log
tail will show this right away, tail | grep will show both 'test1' and 'test2' now



Any hints for me? Thanks in advance

Last edited by WasabiVengeance; 04-22-2008 at 01:23 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 04-22-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The pipe buffers I/O so it won't be printed until the output buffer is full. This is a classic FAQ. Google for "grep unbuffered" for example.
Reply With Quote
  #3  
Old 04-22-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Thank you for your reply, it's much appreciated.

I think I understand the issue, but I don't see an obvious solution in your reply. Should I not be using a pipe? Is there some grep option I should be using, or maybe awk or sed instead?
Reply With Quote
  #4  
Old 04-22-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Some grep implementations have a --line-buffered option which would help. I don't think there is a standard, one-size-fits-all solution to this. Maybe a Perl script to do the tail and grep in the same process; that should certainly avoid any pipe buffering.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0