#!/usr/dt/bin/dtksh #Wrapper script for ckweb.exp. Run it with no argument. #On Solaris, 1983 version of ksh is /usr/dt/bin/dtksh. On other OSes, #it may simply be /bin/ksh or /bin/pdksh. #http://yong321.freeshell.org/freeware/ckweb.html #(C) Copyright 2000,2003 Yong Huang (yong321@yahoo.com) #web site list WEB_LIST=somewhere/ckweb_weblist.txt #You can log site unavailability events FAILLOG=somewhere/ckwebfail.log #ckweb.exp location CKWEB=somewhere/ckweb.exp #Recipient groups: different server availability events are sent to different #people with this grouping. Currently it supports these groups. RCPTA="yong321@yahoo.com" RCPTB="somebody@somewhere.com anotherone@somewhere.com" RCPTC="yetanother" #Add more lines for recipient D,E,F... as needed; remember to add similar lines #about 25 lines down. Next version should address this inconvenience. ### No need to modify below this line unless you need more recipient groups. ### day=$(date +"%w") hour=$(date +"%k%M") #Function to check return status function ckretstat { if (( $3 == 0 )); then print $1 returns code as expected for GET cmd. Good! return elif (( $3 == 1 )); then mailttl="Connection to $1 failed" mailmsg="Connection to $1 immediately failed; its HTTP port may be closed." print -r "$(date '+%Y%m%d %H%M%S'):$1:Connection immediately failed" >> $FAILLOG else # $3 == 2 for timeout mailttl="Connection to $1 failed" mailmsg="$1 may be down or have very poor performance" print -r "$(date '+%Y%m%d %H%M%S'):$1:No response to GET within 30 sec" >> $FAILLOG fi #parse A,B,C into real email addresses rcpts=$(print $2 | tr "," " ") rcpts=$(print ${rcpts/A/$RCPTA}) rcpts=$(print ${rcpts/B/$RCPTB}) rcpts=$(print ${rcpts/C/$RCPTC}) #add more lines for D,E,F... as needed print -r "$mailmsg" | mailx -s "$mailttl" $rcpts } exec 3< $WEB_LIST #Arguments: R: recipients (such as "A" or "A,C") #a: sitename; b: URL; c: port; d: HTTP ret code; e: no check begin day; #f: time g: no check end day; h: time (e,f,g,h specify the time ckweb.exp #won't be called); i: P indicates using proxy (proxy spec is in ckweb.exp) IFS=: while read -r -u3 R a b c d e f g h i; do ck=0 #Check or not: 0 for no, 1 for yes case $R in \#*|"") ;; *) if [[ $e != $g ]]; then #start day != end day if [[ $day -eq $e && $hour -ge $f ]]; then #on start day ck=0 elif [[ $day -eq $g && $hour -le $h ]]; then #on end day ck=0 else #on neither #start and end day not cross week boundary if [[ $e -lt $g ]]; then #and $day between start and end days if [[ $day -gt $e && $day -lt $g ]]; then ck=0 else #$day not between start and end days ck=1 fi #cross week boundary else if [[ $day -lt $g || $day -gt $e ]]; then ck=0 else ck=1 fi fi fi else #same start and end day if [[ $day -eq $e && $hour -ge $f && $hour -le $h ]]; then ck=0 else ck=1 fi fi;; esac if (( $ck == 1 )); then $CKWEB $b $c $d $i ret=$? #if (( $ret != 0 )); then #Uncomment these 4 lines to allow one more test # $CKWEB $b $c $d $i #before sending email alert. # ret=$? #fi case $b in !(*/*)) ckretstat "$a (http://$b:$c)" "$R" $ret;; #No / in URL *) ckretstat "$a (http://${b/\//:$c/})" "$R" $ret;; #Put Port# in correctly esac fi done exec 3<&-