Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server with about 300 virtual hosts. When I want to make sure a specific httpd.conf file is loaded into the Virual Host config and the syntax is correct, I run apachectl -S. The problem is, though, I get a ton of output.

I've tried apacectl -S | grep 'foo' and apachectl -S > foo.txt to try and make this data a little bit more manageable, but the output of the command is not conducive to grepping or shoving into a text file.

When I try apachectl -S | grep 'foo', it simply returns the entire output of apachectl -S.

When I try apachectl -S > foo.txt, foo.txt is an empty file.

This may have something to do with how the server is configured, because I am able to successfully grep on my local machine.

Any suggestions?

share|improve this question
    
What is the prolem you have with the grep output. Show us what you get and tell us why it's not what you want. –  Iain Mar 23 '12 at 15:27
    
Updated. I think this has something to do with how the shell on the server is configured... possibly it's terminating line endings differently? Does that make sense? –  CamelBlues Mar 23 '12 at 16:08
    
what shell are you using, which OS ? –  Iain Mar 23 '12 at 16:10
1  
I'm running bash on CentOS 5.5, so maybe that's not it :( –  CamelBlues Mar 23 '12 at 16:16
    
What you pipe to grep is stdout, are you sure that apachectl -S is dumping to stdout, or stderr? Redirect stderr to stdout, grep on that. –  Marcin Mar 23 '12 at 16:38
add comment

migrated from superuser.com Mar 23 '12 at 15:21

This question came from our site for computer enthusiasts and power users.

2 Answers

up vote 4 down vote accepted

The output of apachectl is sent to stderr. The commands you are using attempt to filter stdout. To use grep in the way you are describing, redirect stderr to stdout, like so:

apachectl -S 2>&1 | grep 'blah'
share|improve this answer
    
Looks like we answered at the same time :) –  CamelBlues Mar 23 '12 at 16:36
add comment

Haha, looks like this question was already answered on Stack Overflow:

http://stackoverflow.com/questions/6505932/how-to-filter-apache-virtual-host-listing-using-grep

Because apachectl -S (which is really a wrapper for httpd -S) sends its output through STDERR, I'm going to need to redirect STDERR to STDOUT, then grep it.

apachectl -S 2>&1 | grep 'foo'

Thanks, S.O.!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.