#!/usr/bin/ksh 
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/svcmd/listdgrp/listdgrp.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2001,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)74        1.4  src/bos/usr/bin/svcmd/listdgrp/listdgrp.sh, uw7cmds, bos720 11/27/07 03:01:04

# FILE DESCRIPTION: High-level command to print the members 
#			of the device groups 
#
#
# RETURN VALUE DESCRIPTION:
#	0 successful
#	1 command syntax incorrect
#	2 device group table could not be opened for reading
#	3 device group could not be found in the device group
#
# EXTERNAL PROCEDURES CALLED: lsdev, grep, rm
#
#
# GLOBAL VARIABLES: Number_of_expected_args
#

Number_of_expected_args=1
PATH=/usr/bin:/usr/sbin:$PATH

###################### cleanup() ##########################
#
# NAME: cleanup()
#
# DESCRIPTION: Called from trap or exit command to clean up 
#		environment and exit.
#
# INPUT: Exit code
#
# OUTPUT: Exit with exit code
#
#

cleanup() {
/usr/bin/rm /tmp/listdgrp.$$ 2>/dev/null
exit $1
}

############### Execution starts from here ################
trap 'cleanup' 0 1 2 15
if [ $# -ne $Number_of_expected_args ] 
then 
	/usr/bin/dspmsg -s 1 sysvlistdgrp.cat 1 'Usage: %s dgroup\n' `/usr/bin/basename $0`  1>&2
	exit 1 
fi

if [ "`echo $1 | /usr/bin/cut -c1`" = - ]
then
	/usr/bin/dspmsg -s 1 sysvlistdgrp.cat 1 'Usage: %s dgroup\n' `/usr/bin/basename $0`  1>&2
        exit 1
else
  	a=`/usr/sbin/lsdev -C -c "$1" 2>/tmp/listdgrp.$$` 
	/usr/bin/grep "lsdev: 0514-518" /tmp/listdgrp.$$ > /dev/null
	if [ $? -eq 0 ]
	then
		cleanup 2
	elif [ "$a" ]
  	then
    		/usr/sbin/lsdev -C -c "$1" | /usr/bin/awk {'print $1'}
		cleanup 0
	else
		/usr/bin/dspmsg -s 1 sysvlistdgrp.cat 2 'Device group not found: %s\n' $1  1>&2
		cleanup 3
  	fi
fi