Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

tail | grep | while read a; waits for EOF

Posted on 2004-07-30
21
Medium Priority
?
1,538 Views
Last Modified: 2011-08-18
Hello,
I would like to have some like that :

tail -f syslog | grep Daemon | while read Message ; do
   echo $Message;
done
Unfortunally it *seems* like grep is buffering the though-flow. Because this
tail -f syslog | while read Message ; do
   echo $Message;
done
works. Except the case that grep is missing. Why does is seem that grep is buffering the through-flow ? It actually waits until I kill the tail process and EOF comes.
HELP PLEASE
Thanks
Dennis
0
Comment
Question by:DennisWood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 6
21 Comments
 
LVL 5

Expert Comment

by:EOL
ID: 11674474
try

 tail -f d.log | grep --line-buffered deamon | while read Message; do echo $Message; done
0
 
LVL 5

Expert Comment

by:EOL
ID: 11674486
found by man grep / buffer, states altough that this could hit performance of the script a little ( obviously )
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674513
tail -f syslog | grep Daemon

should do what you are asking for .... While is not required and It works fine for me (RH8.0) ... It prints the desired lines and gets dynmically updated too
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 5

Expert Comment

by:EOL
ID: 11674757
hm see I suppose he didn't put the "while read" for fun after it, I suppose he's doing something more then echo within.
0
 

Author Comment

by:DennisWood
ID: 11674771
Re EOL:
My grep dos not have the option --line-buffered or simular. I am using Debian 3.0. The grep is version (GNU grep) 2.4.2.
0
 

Author Comment

by:DennisWood
ID: 11674778
Re: Sunnycoder
The echo $Message is replaced by something like :
echo $Message | send to my IM
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674797
Hi Dennis,

tail -f syslog | grep Daemon | send to my IM ... does that work for you?

EOL,
There is no way I would know that ... I prefer not to make any assumptions and tend to start from the most trivial things ... May be cuz that is what I find easier to do ;o)
0
 
LVL 5

Expert Comment

by:EOL
ID: 11674822
Linux 2.6.5-1.358 #1 Sat May 8 09:04:50 EDT 2004 i686 i686 i386 GNU/Linux
grep (GNU grep) 2.5.1

apt-get update grep

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674823
Atleast GNU grep 2.5 onwards supports the line-buffered option ... Is it possible for you to upgrade your grep ?
http://www.gnu.org/software/grep/doc/grep_3.html#IDX73
http://www.gnu.org/software/grep/
0
 
LVL 5

Expert Comment

by:EOL
ID: 11674832
Sunnycoder, I assume people see the obvious before asking, thus I assumed this beeing a simple example, which should work for the sake of extending it later a bit.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674840
We are entitled to hold different opinions and use different approaches.
Peace
0
 
LVL 5

Expert Comment

by:EOL
ID: 11674844
No! Let's fight a little about it ( I loooove fights )
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674856
In that case, I would suggest taking the discussion to a new thread ... Here let us try and get Dennis to the solution he came looking for
0
 
LVL 5

Expert Comment

by:EOL
ID: 11674933
Very constructive!
0
 

Author Comment

by:DennisWood
ID: 11674945
RE EOL:
It does not change anything when I remove the while
0
 

Author Comment

by:DennisWood
ID: 11674949
Ooops it wasd RE Sunnycoder
0
 

Author Comment

by:DennisWood
ID: 11674955
Re EOL:
My debian says it is up-to-date :-)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674962
Hi Dennis,

Download latest grep sources from the link I posted and compile it ... instead of just grep, pass path to this new grep executable ... use --line-buffered as suggested by EOL above and post back the results
0
 
LVL 5

Expert Comment

by:EOL
ID: 11674987
even if removing the while doesn't make a difference, --line-buffered should make one, since it's quite possible that your grep is holding back output, but by specifying --line-buffered, it will put the contents out as soon as a line is finished guaranteed.
0
 

Author Comment

by:DennisWood
ID: 11675170
Okay, I do not really want to download and compile the new grep. Is therefore the only way like ?
tail | grep | while read Message ; do
   if echo "$Message" | grep -q daemon ; then
       echo "$Message" | send to my IM
   fi;
done

Thanks Dennis
0
 
LVL 5

Accepted Solution

by:
EOL earned 750 total points
ID: 11675696
it seems so to me
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question