DennisWood
asked on
tail | grep | while read a; waits for EOF
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
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
found by man grep / buffer, states altough that this could hit performance of the script a little ( obviously )
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
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
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.
ASKER
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.
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.
ASKER
Re: Sunnycoder
The echo $Message is replaced by something like :
echo $Message | send to my IM
The echo $Message is replaced by something like :
echo $Message | send to my IM
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)
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)
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
grep (GNU grep) 2.5.1
apt-get update grep
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/
http://www.gnu.org/software/grep/doc/grep_3.html#IDX73
http://www.gnu.org/software/grep/
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.
We are entitled to hold different opinions and use different approaches.
Peace
Peace
No! Let's fight a little about it ( I loooove fights )
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
Very constructive!
ASKER
RE EOL:
It does not change anything when I remove the while
It does not change anything when I remove the while
ASKER
Ooops it wasd RE Sunnycoder
ASKER
Re EOL:
My debian says it is up-to-date :-)
My debian says it is up-to-date :-)
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
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
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.
ASKER
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
tail | grep | while read Message ; do
if echo "$Message" | grep -q daemon ; then
echo "$Message" | send to my IM
fi;
done
Thanks Dennis
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
tail -f d.log | grep --line-buffered deamon | while read Message; do echo $Message; done