Sunday, 5 June 2016

How to check Apache Web Server Status in Ubuntu with bash script?


##Check Apache Web Server running
is_apache_running(){
        a=$(service apache2 status) >> /dev/null
        if [ "$a" = " * apache2 is running" ];
        then
                _status=0  #echo "Apache WebServer Already Running"
        else
                _status=1  #echo "Apache WebServer is not Running"
        fi
        return $_status
}


##Check Apache Syntax
is_apache_syntax_ok(){

_syntax=$(apache2ctl -t 2>&1)

if [ "$_syntax" = "Syntax OK" ]; then
         _syntax_ok=0
else
         _syntax_ok=1
fi
        return  $_syntax_ok
}

Above snippet is tested under Ubuntu Server 12.x & 14.x.

No comments:

Post a Comment