#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/lpp/cluster/samples/tape/tape_resource_start_example.sh 1.6 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999,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 
# @(#)25  1.6  src/43haes/usr/lpp/cluster/samples/tape/tape_resource_start_example.sh, hacmp.sharedtape, 61haes_r714 11/28/11 15:25:36
#########################################################################
#
#   COMPONENT_NAME: EVENTS
#
#   FUNCTIONS: none
#
#########################################################################

#########################################################################
#
#  Name:  tape_resource_start_example
#
#  Description: This script is an *example* of a 'start' script
#		used to start a highly-available tape resource. 
#		This example simply rewinds the specified tape device.
#
#	In this comment block:  "Called by", "Arguments", and "Returns"
#	sections should not be changed;  the "Calls to" section should
#	be changed to reflect changes in the code.
#
#	In the code, nothing above "BEGIN OPERATION" or below
#	"END OPERATION" should be changed;  everything *between*
#	"BEGIN OPERATION" and "END OPERATION" 
#	may be changed to suit.
#
#  Called by:	cl_tape_resource_get
#
#  Calls to:	Nothing.
#
#  Arguments:	tape_device_name
#
#  Returns:	0       Success
#		1       Failure
#		2	Usage error
#
#########################################################################

#########################################################################
#
# Main Starts Here
#
#########################################################################

# Set flags to provide maximum of debugging information.
#
set -a
eval $(cllsparam -s -n $LOCALNODENAME)
set +a
export PS4='${RG_NAME}:${PROGNAME}[$LINENO] '
[[ "$VERBOSE_LOGGING" = "high" ]] && set -x
[[ "$VERBOSE_LOGGING" = "high" ]] && version='1.5'

# Define a variable we can use in messages.
#
PROGNAME=$(basename ${0})

# Set the path so that we can find cl_get_path
# regardless of whether we are running HAES or 'classic' HACMP.
#
PATH=${PATH}:/usr/sbin/cluster/utilities:/usr/es/sbin/cluster/utilities

# Now set the path so that we can find all other HACMP commands.
# In this example, as originally provided,
# we need this in order to be able to call cl_echo
# in the event of a usage error.
#
PATH="$(cl_get_path all)"
HA_DIR="$(cl_get_path)"
export PATH

# Default exit code is success.
#
STATUS=0

# Test the command-line argument(s).
# If there are too few or too many, report an error
# and exit with a status code indicating failure.
#
if [ $# -ne 1 ]
   then	cl_echo 6261 \
   	"Tape-start script usage: $PROGNAME  tape_device_name\n" $PROGNAME
	exit 2
   fi

set -u

# Define a more reasonable name for the single argument.
#
TAPE_DEVICE_NAME=$1

#################################
#				#
#	BEGIN OPERATION		#
#				#
#################################

# Here is the actual command to rewind the specified tape device.
#
/usr/bin/mt  -f $TAPE_DEVICE_NAME  rewind
STATUS=$?

#################################
#				#
#	END OPERATION		#
#				#
#################################

# Exit with status code
#
exit $STATUS
