Script to check Apache

Austin Godber godber at uberhip.com
Thu Apr 17 15:56:23 MST 2008


you can simply test for the HTTP status code using HEAD

$ HEAD http://10.6.6.1
200 OK
Connection: close
Date: Thu, 17 Apr 2008 22:53:28 GMT
Accept-Ranges: bytes
ETag: "17dea-28b-f5c5a2c0"
Server: Apache/2.0.55 (Ubuntu) mod_ssl/2.0.55 OpenSSL/0.9.8a
Content-Length: 651
Content-Type: text/html; charset=UTF-8
Last-Modified: Wed, 27 Feb 2008 00:33:55 GMT
Client-Date: Thu, 17 Apr 2008 22:53:28 GMT
Client-Peer: 192.168.1.10:80
Client-Response-Num: 1

or

$ HEAD http://10.6.6.1 | head -n 1
200 OK


this comes with the perl LWP package typically ... libwww-perl on ubuntu

Austin


On Apr 17, 2008, at 3:35 PM, Joshua Zeidner wrote:
>  Im going to go with the deceptively simple approach:
>
>  $ps -A | grep httpd | wc -l
>
>  that assumes you have access to the server of course.
>
>  checking active ports remotely can be done with nmap.
>
>  -jmz
>
>
> On Thu, Apr 17, 2008 at 12:54 AM, KevinO <kevin at kevino.org> wrote:
>> Deepan wrote:
>>> Hi All,
>>> I am looking for a script to check if Apache is up
>>> and running, if not the script should send an
>>> email automatically. The script has to be run from
>>> a different machine (not from the machine that
>>> runs apache). So it has to query for a http
>>> address and if it receives any other reply that
>>> 200 OK, it should send the email. Can you guys
>>> suggest on how to go about ? Should I use curl ?
>>> or wget ? or ping ? I can handle the email part
>>> and cron part. If you guys have a similar script
>>> please share it if possible.
>>> Regards
>>> Deepan
>> I used to do this with a small bash script that used wget to fetch  
>> a very small
>> text file from a remote web server, then check the return status  
>> "$?" of the wget
>> command, sending an email out if the exit status was non-zero.
>>
>> Very simple and worked like a champ.
>>
>> --
>> KevinO
>> ---------------------------------------------------
>> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
>> To subscribe, unsubscribe, or to change your mail settings:
>> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>>
>
>
>
> -- 
>
> - http://www.joshuazeidner.com/
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>



More information about the PLUG-discuss mailing list