Httpd – Grepping through the results of apachectl -S

apache-2.2grephttpd

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?

Best Answer

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'
Related Topic