在Linux上安装apache,避免使用AH00558

时间:2015-01-02 12:16:11

标签: linux apache bash

我正在编写一个在Linux上安装Apache2的bash脚本(Ubuntu 14.04)。

echo "Check if Apache is installed"

dpkg -p "apache2" > /dev/null 2>&1

if [ $? != 0 ]; then
    echo "Apache2 is not installed"
    echo "Apache2 installing"
    apt-get -q -y install apache2 > /dev/null
    echo "Apache2 installed"
else
    echo "Apache2 is already installed"
fi

脚本应该是静音的,只应显示“回声”。但我明白了:

Check if Apache is installed
Apache2 is not installed
Apache2 installing
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Apache2 installed

我知道如何在安装后修复AH00558,但我想在安装时禁止警告。

解决方案是什么?

1 个答案:

答案 0 :(得分:1)

将stderr流重定向到/dev/NULL

apt-get -q -y install apache2 2>&1 1> /dev/null

这会让你stdout和stderr重定向到/dev/null