LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-04-2008, 06:28 AM   #1
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
tail and grep issue


I'm trying to access a non-existing page on 'my' webserver. When I run tail -f /var/log/httpd/error_log, I immediately see the error in the log. However, when I run tail -f /var/log/httpd/error_log |grep -v favico |grep -v cc.css, I have to request the non-existing page 5 times before the 5 expected errors are displayed.

Removing one of the 2 greps (it does not matter which one) also gives the expected results.

Can someone explain why this would be the case?


PS 1
The non-existing page is an example, it also happens in other situations.

PS 2
Just in case it's relevant, Slackware 12 without updates and running the commands as root.
 
Old 02-04-2008, 06:48 AM   #2
nileshgr
Member
 
Registered: Aug 2007
Location: Pune, Maharashtra, India
Distribution: Gentoo
Posts: 84

Rep: Reputation: 16
use this-

Code:
tail -f /var/log/httpd/error_log | egrep ^favico$
this should work.
 
Old 02-04-2008, 07:10 AM   #3
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
The delay is probably due to grep performing some sort of buffering as the lines come in. Try using grep --line-buffered or similar.
 
Old 02-04-2008, 11:06 PM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
Thanks for the replies.

@nilesh
Sorry, but your solution did not work; as far as I understand regexps, the '^' in your code indicates beginning of line and not invert result. I might be wrong but I think that that's why it did not work.

@matir
That did the trick.


nilesh' answer however triggered another question.

The man pages state that egrep and grep -e are the same. I however can not figure out how that is the case. From the below, I understand that egrep is a link to another egrep which in turn is a link to grep. Nowhere the -e option is passed which makes me wonder if -e is not the default behaviour of grep.
Code:
wim@lbtd-techweb01:~$ ls -l /usr/bin/egrep
lrwxrwxrwx 1 root root 15 2007-09-19 09:37 /usr/bin/egrep -> ../../bin/egrep*
wim@lbtd-techweb01:~$ ls -l /bin/egrep
lrwxrwxrwx 1 root root 4 2007-09-19 09:37 /bin/egrep -> grep*
wim@lbtd-techweb01:~$ ls -l /bin/grep
-rwxr-xr-x 1 root root 129768 2006-08-07 02:53 /bin/grep*
wim@lbtd-techweb01:~$
 
Old 02-05-2008, 07:16 AM   #5
former33t
LQ Newbie
 
Registered: Feb 2008
Posts: 6

Rep: Reputation: 0
You'll see this often with *nix programs. A single program (one binary with several links to the binary) can be given several names. When the program is run, one of the parameters passed to the program by the OS (even if you don't pass any) is the name of the progam. Running egrep (which invokes the grep binary) internally just does the same thing as passing the -e flag.
 
Old 02-05-2008, 09:51 PM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
Thanks. Your explanation was not 100% clear to me, but other sources filled the missing holes and now it's clear

Quote:
You missed the fact that argv[0] recalls the name of the binary being executed. In other words, grep violates GNU Coding standards (which say that a binary should behave independently of the name it was called by) in order to implicitly turn on -e if invoked by the name 'egrep'.
Thanks again.
 
Old 02-06-2008, 07:19 AM   #7
former33t
LQ Newbie
 
Registered: Feb 2008
Posts: 6

Rep: Reputation: 0
No problem. I was trying to keep it simple and keep terms like argv[0] out of the explanation. Glad it helped.
 
  


Reply

Tags
grep, tail


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 On
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 10:00 AM
how to use grep and tail to get portion of a file laurasong Linux - General 7 08-19-2007 11:59 PM
Weird tail + grep bug Aeiri Linux - Software 2 12-15-2006 05:30 AM
Bash: Script with tail and grep Primsi Linux - General 2 11-16-2006 05:30 AM
Help pls!!! grep or tail->restart poj Linux - Software 3 11-26-2004 12:50 AM


All times are GMT -5. The time now is 01:39 PM.

Main Menu
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