Script help please
George Toft
plug-discuss@lists.plug.phoenix.az.us
Sun, 19 Jan 2003 18:15:45 -0500
Miles Beck wrote:
>
> Hello,
>
> I am in need of a script to check that apache-ssl is still running (and if
> not, email myself and my partner so we can re-start it) until we can figure
> out why it is crashing.
>
> Is there something out there already that will do this?
>
> Or does someone have a script written already that can do the job?
>
> Thanks,
>
> -Miles
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
Here ya go!
I tested on my own server. You might want to change the URL, EMAIL, etc
:) if you have any questions, let me know.
George
#!/bin/bash
# This script monitors a web site ($URL) every $WAIT seconds. If there
is a
# failure, an e-mail is sent to everyone in the $EMAIL list.
#
# Requires package lynx with SSL support (lynx-2.8.4 works for me), some
# kind of mail client (mail or mailx), and date.
#
# Exit codes:
# 1 - lynx not found
# 2 - no mail found
# 3 - no date found
#
# Caveats - this only tests connectivity. If the page is missing, the
server
# returns a 404 and the test passes.
# - The screen will display lynx' stderr, which is probably not
a bad thing :)
#
# Written 01/19/03 George Toft
LYNX=`which lynx`
MAIL=`which mail` # change to mailx if that suits you
DATE=`which date`
URL="https://www.georgetoft.com/index.shtml"
EMAIL="6025551212@mobile.att.net spam@georgetoft.com"
WAIT=60
# Sanity check
if [ "$LYNX" = "" ]; then
echo "I need the lynx package installed, and/or path set to the
lynx binary."
echo
exit 1
fi
if [ "$MAIL" = "" ]; then
echo "I need some mail package installed, and/or path set to the
mail binary."
echo
exit 2
fi
if [ "$DATE" = "" ]; then
echo "I need the date package installed, and/or path set to the
date binary."
echo
exit 2
fi
# Main routine
while [ 1 ]; do
$LYNX -dump "$URL" > /dev/null
if [ $? -ne 0 ]; then
for ADDR in $EMAIL; do
echo "`$DATE "+%F %T"` - Error on $URL" | $MAIL
-s "Error on $URL" $ADDR
done
fi
sleep $WAIT
done