#!/bin/sh

# ###############################################################
# Exceed Connection Server 2008
# Copyright (c) 1997-2008 Hummingbird Ltd. All Rights Reserved.
# ###############################################################
# sessclean
# $Revision: 10408 $
# ###############################################################

# sessclean - clean up all proxy sessions

# some constants
PidFileName=mypid
Proxyname=ewebhost

#process command line
if [ ${1} = "-q" ] ; then
	Quiet=1
	SessionsDir=${2}
else
	Quiet=0
	SessionsDir=${1}
fi

if [ "${SessionsDir}x" = "x" ] ; then
	exit 1
fi

#deal with each session directory 
for dir in `ls $SessionsDir`
do
wholedir="$SessionsDir/$dir"
# kill the process
	if [ -r "$wholedir/$PidFileName" ] ; then
		thispid="`cat $wholedir/$PidFileName 2>/dev/null`"
		if ps -p "$thispid" 2>/dev/null |grep "$Proxyname" > /dev/null 2>&1 ; then
				kill "$thispid" > /dev/null 2>&1
				sleep 5
				kill -9 "$thispid" > /dev/null 2>&1
		fi
	
	fi
# remove the dir
	rm -rf "$wholedir" > /dev/null 2>&1
done

exit

