![]() |
#! /bin/sh
# Name: webmon.sh
# Author: Andowson Chang (andowson [at] gmail [dot] com)
# Version: 0.2
# Created: 2008-02-16
# Last Modified: 2008-02-17
# Description: Web connection monitor (health check)
# If target web server failed, then notify its owner.
# Here email is used for the simplest and cheapest way.
# Usage: webmon.sh <hostname> <owner email>
# Example:
# 1. Single owner:
# /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com
# 2.Multiple onwer:
# /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com,yourboss@yourcompany.com
# 3. Set a cron job to keep checking a web site every few minutes.
# */5 * * * * root /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com,yourboss@yourcompany.com
TARGET=$1
OWNER=$2
WEBMONLOG=/tmp/$TARGET.log
export LANG=en_US
wget -S -t 1 -T 5 http://$TARGET/ -O /tmp/index.html -o $WEBMONLOG
RESULT=`grep "HTTP/1." $WEBMONLOG | awk '{print $2}'`
TIMEOUT=`grep "timed out" $WEBMONLOG | wc -l`
if [ $TIMEOUT == 1 ] || [ ! $RESULT == 200 ]; then
mail -s "[ALERT]$TARGET HTTP connection fail" $OWNER < $WEBMONLOG
fi
# clean up
rm -rf /tmp/index.html
rm -rf $WEBMONLOG
*/5 * * * * root /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com,yourboss@yourcompany.com
檔案名稱 | webmon.sh |
描述 | Website health monitor by shell script |
檔案大小 | 1 Kbytes |
下載次數 | 12 次 |
![]() |