#!/bin/sh
# This script if used by cron job to test whether all instances of gateway are up and
# running.
# Expects the base filename usually - /var/opt/SUNWps/.rp.

SED=/usr/bin/sed

OSTYPE=`/bin/uname -s`
if [ "$OSTYPE" = "Linux" ]; then
  SED=/bin/sed
fi

#Go through the list of port info files

for j in $1*
do
    if [ -r $j ]
    then
        port=`cat $j`
        conf_name=`echo $j | $SED -e "s#$1##"`
        
        for i in $port
        do
            ${BASE_DIR}/${PRODUCT_DIR}/bin/checkport GATEWAY_IPADDR $i $2
            if [ $? -eq 1 ]  
            then
                # At least one port of this instance is not responding.
                /etc/init.d/rwproxyd -n $conf_name start
            fi
        done
    fi
done
