Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

migrated from Mar 23 '12 at 15:21

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

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
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
up vote 7 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

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

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

Your Answer


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.