The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-04-2008 02:41 AM
Badly placed ()'s. - error amitrajvarma Shell Programming and Scripting 3 10-12-2007 04:40 AM
Help with tail /grep needed Felix2511 UNIX for Dummies Questions & Answers 4 05-17-2007 03:22 PM
Constantly updating log files (tail -f? grep? awk?) nortonloaf UNIX for Dummies Questions & Answers 0 12-03-2006 11:20 PM
New to it all, But i wanna script really badly!!! TheNewGuy Shell Programming and Scripting 3 07-03-2004 10:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2008
WasabiVengeance WasabiVengeance is offline
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 04:23 PM..
  #2 (permalink)  
Old 04-22-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #3 (permalink)  
Old 04-22-2008
WasabiVengeance WasabiVengeance is offline
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?
  #4 (permalink)  
Old 04-22-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0