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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-04-2008, 06:28 AM
|
#1
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
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.
|
|
|
02-04-2008, 06:48 AM
|
#2
|
Member
Registered: Aug 2007
Location: Pune, Maharashtra, India
Distribution: Gentoo
Posts: 84
Rep:
|
use this-
Code:
tail -f /var/log/httpd/error_log | egrep ^favico$
this should work.
|
|
|
02-04-2008, 07:10 AM
|
#3
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep:
|
The delay is probably due to grep performing some sort of buffering as the lines come in. Try using grep --line-buffered or similar.
|
|
|
02-04-2008, 11:06 PM
|
#4
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
Original Poster
|
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:~$
|
|
|
02-05-2008, 07:16 AM
|
#5
|
LQ Newbie
Registered: Feb 2008
Posts: 6
Rep:
|
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.
|
|
|
02-05-2008, 09:51 PM
|
#6
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
Original Poster
|
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.
|
|
|
02-06-2008, 07:19 AM
|
#7
|
LQ Newbie
Registered: Feb 2008
Posts: 6
Rep:
|
No problem. I was trying to keep it simple and keep terms like argv[0] out of the explanation. Glad it helped.
|
|
|
All times are GMT -5. The time now is 09:11 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|