linux - 使用命令行工具获取apache服务器版本

标签 linux apache awk grep tr

我使用此命令来获取 apache 服务器版本:

apachectl -V | grep -i“服务器版本”| tr“/”“” | awk '{ print $4 }'

但这并不适用于所有系统。有时我会在服务器版本输出之前得到一些其他输出。

enter image description here

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

问题是为什么我会得到这个输出,即使 grep 应该将其过滤掉?我知道我可以抑制它,但为什么即使我使用 grep 它仍然显示?

最佳答案

该消息可能会发送到标准错误,而不是标准输出。要隐藏它,请将 stderr 重定向到任何地方:

apachectl -V 2>/dev/null | grep ...

关于linux - 使用命令行工具获取apache服务器版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35085506/

相关文章:

Linux 查找目录并只打印名称

linux - 两个具有虚拟接口(interface) ip 的 TCP 客户端应用程序

linux - 在 Shell 中连接字符串

apache - 在 Apache 服务器上运行的 AEM Dispatcher 上缓存视频返回 206

php - 文件上传(在本地工作,但不在远程服务器上)

linux - 查找最大值和最小值并打印文件中的行

bash - 根据两个标准使用 awk 进行过滤

linux - BASH:变量仅显示最后一行

linux - 与另一个 Web 服务器一起运行 Apache?

bash - 使用 Bash 在两个文件之间逐列合并