LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-03-2004, 07:47 AM   #1
apt
Member
 
Registered: Dec 2004
Posts: 34

Rep: Reputation: 15
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.
 
Old 12-03-2004, 07:54 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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.
 
Old 12-03-2004, 08:05 AM   #3
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
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.
 
Old 12-03-2004, 08:10 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
???? you're already giving it an absolute file path! you know where it is!
 
Old 12-03-2004, 08:16 AM   #5
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
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
 
Old 12-06-2004, 11:53 AM   #6
kaito
LQ Newbie
 
Registered: Nov 2004
Location: japan
Distribution: plamo, fedora
Posts: 27

Rep: Reputation: 15
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

Last edited by kaito; 12-06-2004 at 01:24 PM.
 
Old 12-06-2004, 12:34 PM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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
 
Old 12-06-2004, 11:07 PM   #8
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks Kaito and Cedrik,

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to check ftp communication yuva_mca Linux - General 2 12-01-2005 07:15 AM
Shell Script to check root user? kushalkoolwal Programming 4 09-22-2005 12:15 AM
How to check ICMP code through shell script? Thakowbbery Linux - Networking 2 07-19-2005 09:52 AM
Shell script ip address format check. rooch84 Linux - Software 6 08-18-2004 09:14 AM
Shell-Script check if $xx is of type integer d-fens Programming 5 07-11-2003 08:38 AM


All times are GMT -5. The time now is 07:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration