#!/bin/sh
# 
# swscheck.sh  - convenience script to use in crontab or other
# periodic checking mechanism to start all enabled web server daemons.

# Find the path to htserver.  
# Assumes we've been run either under a path, or as an absolute path.
#
# This script is in (possibly nested)
#  	[WHEREVER]/usr/http/bin/swscheck.sh
#
# while htserver is in
#	[WHEREVER]/usr/bin/htserver

CALLED_AS=$0

if [ x"`dirname $CALLED_AS`" != x"." ]; then
	SHORTEN=`dirname $CALLED_AS`
	SHORTEN=`dirname $SHORTEN`
	SHORTEN=`dirname $SHORTEN`
	HTSERVER=$SHORTEN/bin/htserver
else
	HTSERVER=htserver
fi;

TMPFILE=/tmp/swscheck.$$
/bin/rm -f $TMPFILE

$HTSERVER start > $TMPFILE 2>&1

# '3' is the status code returned by htserver in the event
# that it found no action to perform.  In that case all enabled
# servers are already running, and output would simply generate
# useless mail.

if [ $? -ne 3 ]; then
	cat $TMPFILE
fi
/bin/rm -f $TMPFILE

exit 0
