LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Shell Script to Check apache installed or not. (http://www.linuxquestions.org/questions/programming-9/shell-script-to-check-apache-installed-or-not-262115/)

apt 12-03-2004 07:47 AM

Shell Script to Check apache installed or not.
 
OS :- Linux

Using Shell Script, how can i check whether apache is installed in my system, if yes how could i retrive the version no., httpd.conf file path, apachectl file path and httpd file path.

acid_kewpie 12-03-2004 07:54 AM

httpd should be on the filepath, so "httpd --version" will return the version number, and the exit status of that command (echo $?) should be 0 if it is installed, > 0 otherwise.

apt 12-03-2004 08:05 AM

hi acid_kewpie,
Thanks for your reply,

using this statment /usr/sbin/httpd -v i can find the version no. of the apache. but first i need to location the httpd file. how can i get this one.

acid_kewpie 12-03-2004 08:10 AM

???? you're already giving it an absolute file path! you know where it is! :confused:

apt 12-03-2004 08:16 AM

i know this httpd path in my system and to get the information manually,

but i need to design a script which will be excuted in other systems and locate apache installed path and get the listed information automatically.

any help please

kaito 12-06-2004 11:53 AM

Hi, apt:)

How about this shell script?
i think that this script meets your problem.
Code:

#!/bin/sh

# find files
conf=`find / -name httpd.conf`
ctl=`find / -name apachectl`
httpd=`find / -name httpd | grep bin`

### output
# httpd.conf
echo -n "httpd.conf: "
if [ $conf = "" ]
then
        echo "NOT EXIST!!"
else
        echo $conf
fi

# apachectl
echo -n "apachectl: "
if [ $ctl = "" ]
then
        echo "NOT EXIST!!"
else
        echo $ctl
fi

# httpd
echo -n "httpd: "
if [ $httpd = "" ]
then
        echo "NOT EXIST!!"
else
        echo $httpd
        echo ""
        $httpd -v
fi


Cedrik 12-06-2004 12:34 PM

I would rather use a list of usual path for httpd and if the user installed it in an unusual directory, the
script may pause after the search fails and ask the user where httpd is eg :
Code:

#!/bin/bash
KNOWN_PATH="/usr/sbin /sbin /opt/apache2/bin /usr/local/sbin"
HTTPD_DIR=

for path in $KNOWN_PATH; do
    echo "trying $path/httpd..."
    if `ls $path/httpd > /dev/null 2>&1`; then
        HTTPD_DIR=$path
        break
    fi
done

if [ -z $HTTPD_DIR ]; then
    echo "httpd path not found, please enter the path to directory where httpd is"
    echo -n "httpd path : "
    read HTTPD_DIR
fi
HTTPD="$HTTPD_DIR/httpd"

if [ ! -x $HTTPD ]; then
    echo "httpd could not be found, exiting..."
    exit 1
fi
$HTTPD -V


apt 12-06-2004 11:07 PM

Thanks Kaito and Cedrik,

Thanks for the reply. It helped me to learn a lot from your scripts.


All times are GMT -5. The time now is 08:06 AM.