#!/usr/bin/bash IFS=$'\n' SITES=("$@") TIMEOUT=${TIMEOUT:=10} TRIES=${TRIES:=2}3 SAFE=${SAFE:=1} OK_STATUS='2[0-9][0-9]|30[1-9]|401|501' check(){ local comment=`sed \ -e 's/^\(.*\)https\?:\/\/.*$/\1/' \ -e 's/^\s*//;s/\s*$//' \ <<<$1` local target=`sed \ -e 's/^.*\s*\(https\?:\/\/\)/\1/' \ -e 's/^\s*//;s/\s*$//' \ <<<$1` # open port... # nmap $target -Pn -p ssh | grep open # http/https if [ $SAFE ] ; then local safe=--no-check-certificate else local safe fi local response=$(\ wget -S --spider -T $TIMEOUT --tries=$TRIES $safe $target 2>&1 \ | awk '/HTTP\// {print $2}' ) echo "COMMENT=$comment" echo "URL=$target" echo "RESPONSE=$response" } problems= status_pattern="\(${OK_STATUS//|/\\|}\)" for site in ${SITES[@]} ; do IFS=$'\n' \ res=($(check "$site")) comment=${res[0]/COMMENT=/} site=${res[1]/URL=/} res=${res[2]/RESPONSE=/} if [ -z $res ] ; then res='Timeout?' fi ! [ -z $comment ] \ && comment="$comment " #if [ $(grep '\(2[0-9][0-9]\|30[1-9]\|401\|501\)' <<<$res) ] ; then if [ $(grep "$status_pattern" <<<$res) ] ; then state=OK else state="ERROR ($res)" problems=1 fi echo "${comment}${site} : ${state}" done if [ $problems ] ; then exit 1 fi # vim:set ts=4 sw=4 :