我有一个约300个虚拟主机的服务器。 当我想确保一个特定的httpd.conf文件被加载到虚拟主机configuration中,并且语法正确时,我运行apachectl -S 。 问题是,我得到了大量的产出。
我试过apacectl -S | grep 'foo' apacectl -S | grep 'foo'和apachectl -S > foo.txt来尝试使这个数据更容易pipe理一些,但是这个命令的输出不利于对文本文件的格式化。
当我尝试apachectl -S | grep 'foo' apachectl -S | grep 'foo' ,它只是返回apachectl -S的整个输出。
当我尝试apachectl -S > foo.txt ,foo.txt是一个空文件。
这可能与如何configuration服务器有关,因为我能够成功地grep在我的本地机器上。
有什么build议么?
apachectl的输出被发送到stderr。 您正在使用的命令尝试过滤stdout。 要按照您所描述的方式使用grep,请将stderrredirect到stdout,如下所示:
apachectl -S 2>&1 | grep 'blah'
哈哈,看起来这个问题已经在堆栈溢出回答:
https://stackoverflow.com/questions/6505932/how-to-filter-apache-virtual-host-listing-using-grep
因为apachectl -S (它实际上是httpd -S的包装)通过STDERR发送它的输出,所以我需要将STDERRredirect到STDOUT,然后grep它。
apachectl -S 2>&1 | grep 'foo'
谢谢,所以!