: $Workfile:   kixjob.sh  $ $Revision:   1.0  $
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


# usage: kixjob [file ...]
# formats file and sends it to KIXBTCH; removes file

# file(s) to move (optional); default stdin
FILE=
# formatter (default cat)
FORMATTER=cat
# set separator
case `uname -a|cut -f1 -d' '` in
	Windows_NT)
		SEP=';'
		;;
	*)
		SEP=':'
		;;
esac
# collect arguments
set -- `getopt p: $*`

# while	options	to process
while test "$1"	!= "--"
do
    case $1 in
    -p)
	PRINTID=$2
	shift
	;;
    *)
	echo "Invalid Parm $2"
	exit 1
	# illegal option encountered
	;;
    esac
    shift
done

# skip --
shift

# all arguments	are files to go to batch
FILE="$*"

# if no	file given, assume stdin
if test	-z "$FILE"
then
    FILE="-"
    RMCMD=
else
    # must remove file after printing
    RMCMD="/bin/rm -f	$FILE"
fi

if test -z "$KIXBTCH"
then
    echo "KIXBTCH is not set.  Job $FILE left in KIXSYS" >&2
    exit 0
fi

# The shell will not be executed unless its mode is executable 

chmod 755 $FILE

# If KIXBTCH has multiple directories, strip off all but the first
# If KIXBTCH contains a time, strip it off also

#BTCHDIR=`echo "$KIXBTCH" | cut -f1 -d":" | cut -f1 -d"["` 
BTCHDIR=`env | grep KIXBTCH | cut -f2 -d"=" | cut -f1 -d"$SEP"` 

# Move the file to the batch directory for execution

mv $FILE $BTCHDIR
exit $?
