#!/bin/sh
#
# @(#)stopsrje.sh	8.7 8.7 93/11/17 Copyright 1986-1993 SMI
#
#        Copyright (c) 1993, Sun Microsystems, Inc.  All Rights Reserved.
#        Sun considers its source code as an unpublished, proprietary
#        trade secret, and it is available only under strict license
#        provisions.  This copyright notice is placed here only to protect
#        Sun in the event the source is deemed a published work.
# 
#        RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
#        Government is subject to restrictions as set forth in subparagraph
#        (c)(1)(ii) of the Rights in Technical Data and Computer Software
#        clause at DFARS 52.227-7013 and in similar clauses in the FAR and
#        NASA FAR Supplement.
#
# Shutdown SunLink SNA RJE.  This script kills the SNA RJE process
# specified by the gateway name 
#

ME=`id | awk '{proc = substr($0,7,4); if (proc = "root") print proc }'`
if [ "$ME" != "root" ]
then
    echo "You must be root to run this script."
    exit 1
fi

if [ $# != 1 ]
then
	echo "usage: stopsnarje <-a | gateway>"
	echo "       where -a indicates all gateways"
	exit 1
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/etc:/usr/etc
export PATH

case $1 in
	-*) 	
		if [ "$1" = "-a" ]
		then 
           	        psid=`ps -ef | awk 'NF >= 1 { if ($(NF-1) == "sna3770") print $2}'`
           	        pgmnm=`ps -ef | awk 'NF >= 1 { if ($(NF-1) == "./sna3770" || $(NF-1) == "sna3770" ) print $(NF-1) " " $(NF) }'`
			if [ "$psid" != "" ]
			then
			    echo "Terminating: $pgmnm"
	       		    kill $psid
			fi
		else
			echo "usage: stopsnarje <-a | gateway>"
			echo "       where -a indicates all gateways"
			exit 1
		fi
		;;
	*)	
		gateway=$1
           	psid=`ps -ef | awk 'NF >= 1 { if (($(NF-1) == "./sna3770" || $(NF-1) == "sna3770")  && $(NF) == gateway) print $2}' gateway=$1`
           	pgmnm=`ps -ef | awk 'NF >= 1 { if (($(NF-1) == "./sna3770" || $(NF-1) == "sna3770")  && $(NF) == gateway) print $(NF-1) " " $(NF) }' gateway=$1`
		if [ "$psid" != "" ]
		then
			echo "Terminating: $pgmnm"
	       		kill $psid
		fi
		;;
esac

if [ "$psid" = "" ]
then
	if [ $1 = "-a" ]
	then 
		echo "stopsnarje: no gateway found"
	else
		echo "stopsnarje: no gateway \"$1\" found"
	fi
fi
