#!/usr/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/cdat/smit/cdat_rm_sched_coll.sh 1.3 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010,2011 
# 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 
# @(#)42    1.3  src/bos/usr/bin/cdat/smit/cdat_rm_sched_coll.sh, cdat, bos720 7/14/11 17:40:11
# This command removes the specified collect in the cdat user cronfile
#

PATH=/bin:/sbin:/usr/bin:/usr/sbin
CAT=cdat.cat
REP=0

usage() {
	echo "Usage: $0 -i <collect name>"
}

if [ $# -ne 2 ]
then
	# should not happen under smit
	usage
	exit 1
fi
if [ "$1" != "-i" ]
then
	# should not happen under smit
	usage
	exit 1
fi

COLLECT=$2
if [ -z "$COLLECT" ]
then
	# should not happen under smit
	usage
	exit 1
fi

MUSER=`/usr/lib/cdat/smit/cdat_init_values | sed -n 2p | sed -ne 's/:.*$//p'`
crontab -l $MUSER > /tmp/cdat_cronfile$$
[ $? -ne 0 ] && exit 4
cat /tmp/cdat_cronfile$$ 2>/tmp/cdat_error$$ | grep -v \
"/usr/bin/cdat[ 	]*collect[ 	].*[ 	'\"]-i[ 	'\"]*${COLLECT}[ 	'\"]" 2>>/tmp/cdat_error$$ 1>/tmp/cdat_cronfila$$
if [ "`wc /tmp/cdat_error$$ | awk '{print $1}'`" -ne 0 ]
then
	cat /tmp/cdat_error$$ >&2
	rm -f /tmp/cdat_error$$ /tmp/cdat_cronfil?$$
	exit 4
fi
rm -f /tmp/cdat_error$$
mv /tmp/cdat_cronfila$$ /tmp/cdat_cronfile$$
if [ $? -ne 0 ]
then
	rm -f /tmp/cdat_cronfil?$$
	exit 3
fi
if [ "$USER" != "$MUSER" ]
then
	su "$MUSER" -c crontab /tmp/cdat_cronfile$$
	[ $? -ne 0 ] && REP=10
else
	crontab /tmp/cdat_cronfile$$
	[ $? -ne 0 ] && REP=5
fi

rm /tmp/cdat_cronfile$$
exit $REP
