#!/bin/csh
#	@(#)termapp	1.3	09/08/97
#
#
#     $Id: termapp,v 1.1 1998/03/16 20:03:02 avvede Exp $
#     $Log: termapp,v $
#     Revision 1.1  1998/03/16 20:03:02  avvede
#     Initial move to CVS
#
#
#
#
#	Copyright (c) 1986, 1987, 1988 by
#	Periphonics Corporation
#	4000 Veterans Memorial Highway
#	Bohemia
#	NY 11716
#
#	This software is furnished under a license and may be used and
#	copied only in accordance with the terms of such license and with
#	the inclusion of the above copyright notice. This software or any
#	other copies thereof, may not be provided or otherwise made available
#	to anyone other than the licensee. Title to and ownership of this
#	software remains with the Periphonics Corporation.
#
#	The information in this document is subject to change without notice
#	and should not be construed as a commitment by Periphonics.
#
#	Periphonics assumes no responsibility for the use or reliability of
#	its software on equipment that is not supplied by Periphonics.
#
#	File Name:
#		termapp
#
#	Description:
#		Procedure to produve VRAM applications.
#		See usage line below.
#
#	Change				Reason
#	No.	Date		Name	for Change
#
#	0	19-mar-92	lmg	Original.
#	1	01-apr-92	lmg	Quote $1 in set.
#	2	15-mar-94	lmg	Fixed for /usr/ucn/ps.
#	3	08-sep-97	lmg	Changed tp /usr/ucb/ps.
#
#
#	termapp - A procedure to terminate applications
#
#	set up command name
#
if ($?0 == 0) then
	set cmd=termapp
else
	set cmd=$0
endif
#
#	check argument count
#
if ($#argv < 1) then
usage:
	echo "usage: $cmd [-h | -s SIGNAL] application_name [identifyingstring]"
	exit 1
endif
#
#	decode signal flag
#	-h signal TERM
#	-s SIG
#
if ("$1" == "-h") then
	if ($#argv < 2) then
		goto usage
	endif
	set sig=TERM
	shift
else if ("$1" == "-s") then
	if ($#argv < 3) then
		goto usage
	endif
	set sig=$2
	shift
	shift
else
	set sig=INT
endif
#
#	set grep arguments
#
if ($#argv < 2) then
	set grepexp="$1"
else
	set grepexp="(($1).*($2))|(($2).*($1))"
endif
#
#	First, look in the ps for all lines containing the requested
#	strings.  Then, throw away the greps, convert to kill commands
#	and execute them.
#
#set what=`which ps | grep ucb`
#if ( "$what" == "" ) then
#	set arg=-ef
#	set comm=`echo print \"kill -$sig \" '$2'` #$2 is an arg for AWK
#else
#	set arg=-ax
#	set comm=`echo print \"kill -$sig \" '$1'`
#endif

set comm=`echo print \"kill -$sig \" '$3'`	# $3 is an arg for AWK
/usr/ucb/ps -axwwl | \
egrep -e "${grepexp}" | egrep -v "grep|csh" | \
awk "{$comm}" | sh
