ftp_transfer.prog
-
#!/bin/sh
-
# xxgc_ftp_transfer2.prog v1.0 Thur 4 Sep 2008
-
# Author: Robert Metcalf
-
#
-
# 1.0 initial version
-
#Executable: XXGCFTPTRANS2
-
#CR: Greenwich FTP transfer Process 2
-
# $0 - Shellscript name
-
# $1 - Oracle username/password
-
# $2 - User_id
-
# $3 - Oracle Applications username
-
# $4 - Concurrent request id
-
-
LOGFILE=$COMMON_TOP/admin/$APPLLOG/l$4.req
-
-
OUTFILE=$COMMON_TOP/admin/$APPLOUT/o$4.out
-
if [ $APPCPNAM = 'USER.REQID' ]; then
-
#Output file name is in the format USERNAME.######
-
#See bottom of page 8
-
OUTFILE=$COMMON_TOP/admin/$APPLOUT/$3.$4
-
fi
-
-
#$5 = src dir (full path from root with trailing slash) '/apps11i/dev/devcomn/admin/out/DEV_gchrdev/'
-
#$6 = src file name (File name to transfer) 'o2992771.out'
-
#$7 = Dest DIR (where to go) 'BST, Finance, HR'
-
#$8 = dest file name
-
#$9 = FTP Host Name:::FTP Username :::FTP Password
-
-
I_SRC_DIR=$5
-
I_SRC_FIL=$6
-
I_DEST_DIR=$7
-
I_DEST_FIL=$8
-
I_FTP_HOST=`echo $9 | awk -F ::: '{print $1}'`
-
I_FTP_USER=`echo $9 | awk -F ::: '{print $2}'`
-
I_FTP_PASS=`echo $9 | awk -F ::: '{print $3}'`
-
-
echo "xxgc_ftp_transfer2.prog running" >> $LOGFILE
-
echo "script being run as:" >> $LOGFILE
-
whoami >> $LOGFILE
-
echo "TWO_TASK: " $TWO_TASK >> $LOGFILE
-
echo "Source Dir: " $I_SRC_DIR >> $LOGFILE
-
echo "Source File name: " $I_SRC_FIL >> $LOGFILE
-
echo "Dest Dir: " $I_DEST_DIR >> $LOGFILE
-
echo "Dest File name: " $I_DEST_FIL >> $LOGFILE
-
echo "FTP Host: " $I_FTP_HOST >> $LOGFILE
-
echo "FTP User: " $I_FTP_USER >> $LOGFILE
-
echo "FTP Pass: ******" >> $LOGFILE
-
echo "See output for processing messages" >> $LOGFILE
-
-
echo "xxgc_ftp_transfer2.prog running" >> $OUTFILE
-
echo "script being run as:" >> $OUTFILE
-
whoami >> $OUTFILE
-
echo "TWO_TASK: " $TWO_TASK >> $LOGFILE
-
echo "Source Dir: " $I_SRC_DIR >> $OUTFILE
-
echo "Source File name: " $I_SRC_FIL >> $OUTFILE
-
echo "Dest Dir: " $I_DEST_DIR >> $OUTFILE
-
echo "Dest File name: " $I_DEST_FIL >> $OUTFILE
-
echo "FTP Host: " $I_FTP_HOST >> $OUTFILE
-
echo "FTP User: " $I_FTP_USER >> $OUTFILE
-
echo "FTP Pass: ******" >> $OUTFILE
-
-
#Check TWO_TASK is set correctly
-
if [ "E" = E$TWO_TASK ]; then
-
echo "ERROR - TWO_TASK is not set" >> $OUTFILE
-
echo "TWO_TASK must be set for this command to run" >> $OUTFILE
-
exit 1
-
fi
-
loc_ok=0
-
for X in "PROD" "TEST" "SUPPORT" "DEV" "TRAIN"
-
do
-
if [ $X = $TWO_TASK ]; then
-
loc_ok=1
-
fi
-
done
-
if [ $loc_ok = 0 ]; then
-
echo "TWO_TASK is not correctly set." >> $OUTFILE
-
echo "TWO_TASK = $TWO_TASK" >> $OUTFILE
-
exit 1
-
fi
-
-
TMP=`echo $I_SRC_DIR | sed -n 's/\(^.[^$]*\)\(.\{1\}$\)/\2/p'`
-
if [ $TMP != "/" ]
-
then
-
echo "Source dir dosn't end with / (" $I_SRC_DIR ")" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`echo $I_SRC_DIR |cut -c1-1`
-
if [ $TMP != "/" ]
-
then
-
echo "Source dir dosn't start with / (" $I_SRC_DIR ")" >> $OUTFILE
-
exit 1
-
fi
-
-
if [ "PROD" != $TWO_TASK ]
-
then
-
I_DEST_FIL="TEST_FILE_"$TWO_TASK"_"$I_DEST_FIL
-
echo "Non prod, changed Dest File name to: " $I_DEST_FIL >> $OUTFILE
-
fi
-
-
if [ ! -d $I_SRC_DIR ]; then
-
echo "ERROR - Can't find the source directory (" $I_SRC_DIR ")" >> $OUTFILE
-
exit 1
-
fi
-
-
if [ ! -f $I_SRC_DIR$I_SRC_FIL ]; then
-
echo "Source file does not exist (" $I_SRC_DIR$I_SRC_FIL ")" >> $OUTFILE
-
exit 1
-
fi
-
-
loc_ok=0
-
for X in "BST" "Finance" "HR"
-
do
-
if [ $X = $I_DEST_DIR ]; then
-
loc_ok=1
-
fi
-
done
-
if [ $loc_ok = 0 ]; then
-
echo "Dest dir must be one of ""BST"" ""Finance"" ""HR""" >> $OUTFILE
-
echo "Dest dir = $I_DEST_DIR" >> $OUTFILE
-
exit 1
-
fi
-
I_DEST_DIR=$I_DEST_DIR "/"
-
-
echo "Checks passed, attempting transfer..." >> $OUTFILE
-
-
#************************************************END OF CHECKS ACTUALL CODE TO DO TRANSFER*****************************
-
-
$XXGC_TOP/bin/ftp_call2.sh $I_SRC_DIR $I_SRC_FIL $I_FTP_HOST $I_DEST_DIR $I_FTP_USER $I_FTP_PASS $I_DEST_FIL >> $OUTFILE
-
-
TMP=`grep "Not connected" $OUTFILE`
-
if [ "E" != E$TMP ]; then
-
echo "ERROR - is the hostname correct?" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`grep "Login failed" $OUTFILE`
-
if [ "E" != E$TMP ]; then
-
echo "ERROR - the FTP login failed. Is the username and password correct?" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`grep "File not found" $OUTFILE`
-
if [ "E" != E$TMP ]; then
-
echo "ERROR - File not found - Transfer failed" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`grep "No such file or directory" $OUTFILE`
-
if [ "E" != E$TMP ]; then
-
echo "ERROR - No such file or directory - Transfer failed" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`grep "Cannot create a file when that" $OUTFILE`
-
if [ "E" != E$TMP ]; then
-
echo "ERROR - Can't create file. Try deleting contents or ftp dir - Transfer failed" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`grep "250 RNTO command successful" $OUTFILE`
-
if [ "E" = E$TMP ]; then
-
echo "ERROR - No sucessful rename found - Transfer failed" >> $OUTFILE
-
exit 1
-
fi
-
TMP=`grep "426 Connection closed; transfer aborted" $OUTFILE`
-
if [ "E" != E$TMP ]; then
-
echo "ERROR - The transfer aborted. This could be because there is not enough disk space availible" >> $OUTFILE
-
echo "on the ftp drive" >> $OUTFILE
-
echo "The FTP drive should be used as a transfer location only, not to store files" >> $OUTFILE
-
echo "Clear down the directory and retry" >> $OUTFILE
-
echo "If this does not work call system support" >> $OUTFILE
-
exit 1
-
fi
-
-
echo "FTP Transfer operation completed sucessfully" >> $OUTFILE
-
-
exit 0
ftp_call2.sh
-
#echo $username $password $target_server
-
# start the copy
-
cd $1
-
USER=$5
-
PASSWD=$6
-
ftp -i -n -d $3 <<SCRIPT
-
user $USER $PASSWD
-
verbose
-
cd $4
-
delete "$2"
-
delete "$7"
-
put "$2"
-
rename "$2" "$7"
-
quit
SCRIPT
Misc
Note: Create this file in $XXGC_TOP/bin as ftp_transfer.prog
Then run symbolic link code
RJM Article Type
Quick Reference