http://qs1969.pair.com?node_id=721915


in reply to Getting Apache Version

I'd probably first scan the machine for apachectl or apache2ctl and when found, launch it with a '-v' flag. That'll show you information like (two random test servers):

$ apachectl -v
Server version: Apache/2.2.4 (FreeBSD)
Server built:   May 18 2008 17:19:41

and

$ apache2ctl -v
Server version: Apache/2.2.3
Server built:   Mar 22 2008 09:29:10

Easy enough to parse that, I assume ;-)

--
b10m

Replies are listed 'Best First'.
Re^2: Getting Apache Version
by ultranerds (Hermit) on Nov 06, 2008 at 09:23 UTC
    Hi, Thanks for the reply guys. From the sounds of it, there is no "simple" way of doing this. I think the approach I'm gonna take is putting some examples in "comments" inside the script, so they can test the different paths themselves (and if needed, as their host). So something like:
    my $path = 'apachectl'; my $output = `$path -v`; my @split = split /:/, $output; if ($split[1] !~ /\d\.\d\.\d/) { print qq|Cant find Apache version <br />|; } else { print qq|$split[1] <br />|; }
    Thanks guys. Andy
Re^2: Getting Apache Version
by ultranerds (Hermit) on Nov 06, 2008 at 09:59 UTC
    Damn it - won't work :(
    #!/usr/bin/perl # example paths can be: # apachectl # apache2ctl # httpd my $path = 'httpd'; print "Content-Type: text/html \n\n"; print "Perl: " . $] . "<br />"; my $output = `$path -v`; my $output2 = system(qq|$path -v|); print "OUTPUT: ($path -v) " . $output . "<br />"; print "OUTPUT 2: ($path -v, as system()) " . $output2 . "<br />"; my @split = split /:/, $output; if ($split[1] !~ /\d\.\d\.\d/) { print qq|Cant find Apache version <br />|; } else { print qq|$split[1] <br />|; }
    ..yet all that gives is:
    Perl: 5.008004 OUTPUT: (httpd -v) OUTPUT 2: (httpd -v, as system()) -1 Cant find Apache version
    Seems that it doesn't like giving the results with `` or system(). Any suggestions? TIA Andy
      Anyone got any suggestions? :/

      Cheers

      Andy
        I don't see where you check error messages, or check that httpd is in the path and readable and executable by current user