Search the world wide web...
Google
 

Saturday, January 7, 2012

CA – XCOM : Script example in AIX

This is an example on how to create a shell script in AIX to transfer file using XCOM tool. Pre-requisite for this task is to have:
1) CA – XCOM installed successful
2) To have necessary access to execute xcomtcp command\

To execute XCOM file transfer, xcomtcp command is the syntax to be used and a few options for the file transfer setting. Create an empty file i.e. test.sh and put the following script:

cd /app/xcom/test
#Delete status file if exist
if [ -f success.txt ];
then
rm success.txt

elif [ -f fail.txt ]
then
rm fail.txt
fi


#Start file transfer
xcomtcp -c1 -f test.cnf LOCAL_FILE=./test.txt REMOTE_FILE=C:/test/test.txt PROTOCOL=TCPIP XENDCMD=./status.sh

In above example script, two status file will be deleted first if they exist. success.txt is the success file and fail.txt will be generated if the transfer file failed. Both file creation will be written in status.sh script file.

In xcomtcp command above, test.cnf configuration file will be used. There are a lot of option in the config file that can be use, for example userid and password. If you want to override the setting in config file, just write it in the xcomtcp command as above. In above example, attribute that being overide is the local file, remote file and protocol setting in config file with the value stated in the example. XENDCMD is actually in xcom.glb file, which is the another config file for XCOM. It’s function is to execute script once file transfer is done.

Below are the status.sh sample scipt to be executed after xcomtcp command is completed:

# This procedure is invoked by the Unicenter CA-XCOM Data Transport transfer
# program after the transfer is finished (whether successful or not).
# Not every argument will be populated;
# the values contained in the arguments depend on those provided by the
# remote system.
###### START OF DEBUG SECTION ######
######
###### UNCOMMENT THE LINES BELOW TO DEBUG THIS SCRIPT ######
#exec > /tmp/xcomend.$1.out
#exec 2>&1
#set -vx
#PS4='[$0: $LINENO]+ '
#export PS4
###### END OF DEBUG SECTION ######
#
# The first parameters are supplied for any type of transfer.


local_reqno=$1 # local request number/tid (000000 if unassigned)
shift
initiator=$1 # LOCAL or REMOTE
shift
transfer_type=$1 # FILE or JOB or REPORT
shift
direction=$1 # SEND or RECEIVE
shift
restarting=$1 # RESTARTING or FIRST_TRY
shift
start_time=$1 # Start time of transfer
shift
end_time=$1 # End time of transfer
shift
remote_system=$1 # Remote system name
shift
status=$1 # Status of transfer
shift
error=$1 # XCOM file transfer numeric error code
shift
msg=$1 # error code translated to message text
shift
status_msg=$1 # status message from partner when error on remote sys
shift
remoteuser=$1 # Remote user
shift
remote_reqno=$1 # Remote request Number
shift
group=$1 # Group name
shift
sysdata=$1 # System Dependent User Data
shift
xferdata=$1 # Transfer Dependent User Data
shift
transfer_name=$1 # Transfer Name
shift
tmp_file=$1 # Local temporary file name
shift
file=$1 # Local file name
shift
remote_file=$1 # Remote file name
shift
carriage_flag=$1 # Carriage return flag
shift
code_flag=$1 # Code flag
shift
compression=$1 # Compression flag
shift
file_recs=$1 # No. of records read/written
shift
file_bytes=$1 # No. of bytes read/written
shift
blocks=$1 # No. of blocks sent/received
shift
bytes=$1 # No. of bytes sent/received
shift
#


# The next parameters are supplied for file transfers only
if [ $transfer_type = "FILE" ]
then
fileaction=$1 # File action (C, R, or A for create, replace, or append)
shift
datasettype=$1 # Dataset type
shift
recfm=$1 # Record format
shift
lrecl=$1 # Logical record length
shift
truncation_flag=$1 # Truncation flag
shift
#
# The next group of parameters are supplied for report transfers only
elif [ $transfer_type = "REPORT" ]
then
jobname=$1 # Job name field from JES
shift
jobnumber=$1 # Job number field from JES
shift
class=$1 # print class
shift
copies=$1 # Number of copies to print
shift
form=$1 # Type of form to print this job on.
shift
recfm=$1 # Record format of incoming print job.
shift
lrecl=$1 # Logical record length of incoming report.
shift
blksize=$1 # Block size of incoming report.
shift
ucs_name=$1 # Name of UCS to be used for this print job.
shift
fcb=$1 # Name of FCB (form control block) for this report.
shift
room_number=$1 # Room number field from JES.
shift
programmer_name=$1 # Programmer name field from JES.
shift
tso_notify=$1 # TSO notify field from JES.
shift
destination=$1 # Destination printer specification.
shift
carriagecontrol=$1 # Type of carriage control characters being used.
shift
#
# There are no extra parameters for remote jobs
fi
#


# PUT YOUR OWN XCOM ENDING CODE HERE !
if [ $status = "SUCCESSFUL" ]
then
echo 'Start time : ' $start_time >> success.txt
echo 'End time : ' $end_time >> success.txt
echo 'File name : ' $file >> success.txt
elif [ $status = "FAILED" ]
then
echo 'Start time : ' $start_time >> fail.txt
echo 'End time : ' $end_time >> fail.txt
echo 'Error message : ' $msg >> fail.txt
echo 'Remote error message : ' $status_msg >> fail.txt
echo 'File name : ' $file >> fail.txt
fi
exit 0

Give focus on few line of code at the end of the script. After # PUT YOUR OWN XCOM ENDING CODE HERE ! comment, you can put your own script on how to manipulate all variable define in the beginning of the script into your own.