Article Listing 1 Listing 2 sep2004.tar

Listing 1 web-server-status.sh

#!/bin/sh

PATH=/bin:/usr/local/bin:/usr/local/ssl/bin ; export PATH

# The following variable defines which host to connect to
HOST="www.example.com"

# The following variable defines the port to connect to on HOST
PORT="443"

#  Where to send E-mail with results
ADMIN="pageme@mydomain.net"

TMP="$HOME/connect.$$"

umask 077
touch ${TMP}

openssl s_client -quiet -connect ${HOST}:${PORT} > ${TMP} 2>&1 << EOF
GET / HTTP/1.0


EOF

if egrep "Server:" ${TMP} > /dev/null
then
        :
else
        logger -p daemon.notice "Failed to connect to ${HOST} on Port ${PORT}"
    echo "Failed to initiate SSL connection to ${HOST} on ${PORT}" \
        | /bin/mail -s "$0: Failed to connect to secure server \
    on ${HOST}:${PORT}" ${ADMIN}
fi

rm -f ${TMP}