如何使用 grep 过滤 Apache 虚拟主机列表
我有一个配置了许多虚拟主机的 Apache 服务器,并且希望能够像这样使用 grep 来过滤它们......
# httpd -S | grep "myStr"
但是,这种方法不起作用 - 我仍然看到列出的所有虚拟主机。我有什么想法可以真正做到这一点吗?
这是 httpd -S 的输出示例
[root@224136 config]# httpd -S
VirtualHost configuration:
184.22.xxx.33:80 is a NameVirtualHost
default server default (/etc/httpd/conf/kloxo/default.conf:4)
port 80 namevhost default (/etc/httpd/conf/kloxo/default.conf:4)
port 80 namevhost webmail (/etc/httpd/conf/kloxo/webmail.conf:6)
port 80 namevhost xxxxxx.com (/home/httpd/xxxxxx.com/conf/kloxo.xxxxxxx.com:4)
port 80 namevhost twptest.xxxxxx.com (/home/httpd/twptest.xxxxxx.com/conf/kloxo.twptest.xxxxxx.com:4)
port 80 namevhost yyyyyyy.com (/home/httpd/yyyyyy.com/conf/kloxo.yyyyyyy.com:4)
port 80 namevhost zzzzzzzz.com (/home/httpd/zzzzzzz.com/conf/kloxo.zzzzzzzz.com:4)
port 80 namevhost expenses.zzzzzzzz.com (/home/httpd/expenses.zzzzzzz.com/conf/kloxo.expenses.zzzzzzz.com:4)
port 80 namevhost aaaaaaaa.cz (/home/httpd/aaaaaaaaaaaa.cz/conf/kloxo.aaaaaaaaaaa.cz:4)
port 80 namevhost aaaaaaaaaaa.cz (/home/httpd/aaaaaaaaaaaaa.cz/conf/kloxo.aaaaaaaaaa.cz:142)
I have an Apache server configured with many virtual hosts and would like to be able to filter them using grep like so..
# httpd -S | grep "myStr"
.. however, this approach doesn't work - I'm still seeing all my virtual hosts listed. Any ideas how I can actually do this?
Here's a sample of the output from httpd -S
[root@224136 config]# httpd -S
VirtualHost configuration:
184.22.xxx.33:80 is a NameVirtualHost
default server default (/etc/httpd/conf/kloxo/default.conf:4)
port 80 namevhost default (/etc/httpd/conf/kloxo/default.conf:4)
port 80 namevhost webmail (/etc/httpd/conf/kloxo/webmail.conf:6)
port 80 namevhost xxxxxx.com (/home/httpd/xxxxxx.com/conf/kloxo.xxxxxxx.com:4)
port 80 namevhost twptest.xxxxxx.com (/home/httpd/twptest.xxxxxx.com/conf/kloxo.twptest.xxxxxx.com:4)
port 80 namevhost yyyyyyy.com (/home/httpd/yyyyyy.com/conf/kloxo.yyyyyyy.com:4)
port 80 namevhost zzzzzzzz.com (/home/httpd/zzzzzzz.com/conf/kloxo.zzzzzzzz.com:4)
port 80 namevhost expenses.zzzzzzzz.com (/home/httpd/expenses.zzzzzzz.com/conf/kloxo.expenses.zzzzzzz.com:4)
port 80 namevhost aaaaaaaa.cz (/home/httpd/aaaaaaaaaaaa.cz/conf/kloxo.aaaaaaaaaaa.cz:4)
port 80 namevhost aaaaaaaaaaa.cz (/home/httpd/aaaaaaaaaaaaa.cz/conf/kloxo.aaaaaaaaaa.cz:142)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
既然你说“我仍然看到列出的所有虚拟主机”,我怀疑你需要将 STDERR 重定向到 STDOUT,如下所示(假设 bash)
out.py
只是一个写入一些输出的 pythonscript使用 sys.stderr.write() 发送到 STDERR现在将 STDERR 发送到 STDOUT:
Since you say that "I'm still seeing all my virtual hosts listed" I suspect you need to redirect STDERR to STDOUT as seen below (assuming bash)
out.py
is just a pythonscript that writes some output to STDERR usingsys.stderr.write()
Now send STDERR to STDOUT:
我只是有同样的需求,并使用了以下内容:
它在让 awk 清理它之前将 SDTERR (2) 重定向到 STDOUT (&1)
I just had the same need, and used the following:
It redirects SDTERR (2) into STDOUT (&1) before getting awk to clean it up