#!/bin/sh -x
#
# routine:      NETCPY.SH
#
# purpose:      Script file which can be run as a pipeline process
#               in order to automate retrieval of files from a
#               remote host.
#
# modification history:
#
#   date    opr     who     reason
# -------- -----  --------  --------------------------------------      
# 05/26/98 35570  MSwam     port to UNIX
# 08/04/03 49086  Rose      WFC3: move files to the dat/dct directory
# 09/24/03 49086_01 Rose    Get passwd on solaris
# 09/29/03 49086_02 Rose    Don't send mail on smalls
# 06/30/10 65423  MSwam     Use netcopy/SFTP
#
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
banner=">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo $banner
date
#
# define error/exit status values
all_is_well=1
netcpy_success=3
netcpy_no_files=5
netcpy_files_missing=7
netcpy_copy_failed=9
netcpy_usage_error=11
netcpy_insuff_disk=13
netcpy_failed_delete=15
go_absent=102
#
#
# run the cdbcopy file transfer tool
netcopy -rm $REMOTE_MACHINE -rl $REMOTE_LOGIN -ds $DISK_SLOP_PERC -te $TEMP_DIR -rf ${REMOTE_FILESPEC} -delete_after_copy -lf ${LOCAL_FILESPEC} -pg $PUT_OR_GET
savestat=$?
#
# exit if no files found (send no e-mail either)
if [ $savestat = $netcpy_no_files ]
then
   echo $banner
   exit $all_is_well
fi
#
# Send a mail message indicating the status of the NETCPY run.
#-- create the mail message based on the NETCPY exit status
#
estatus=$all_is_well

if [ $savestat = $netcpy_success ]
then
#   cd /info/devcl/pipe/erith/tv/dat
   cd $LOCAL_FILESPEC
   mv CSII*osc dct
   mv CSII*SDI dct
   mail_subject="NETCPY: SUCCESS"
elif [ $savestat = $netcpy_files_missing ]
then 
   mail_subject="NETCPY: Files MISSING"
elif [ $savestat = $netcpy_copy_failed ]
then 
   mail_subject="NETCPY: Copy FAILED"
elif [ $savestat = $netcpy_usage_error ]
then 
   mail_subject="NETCPY: USAGE error"
elif [ $savestat = $netcpy_insuff_disk ]
then 
   mail_subject="NETCPY: INSUFF DISK SPACE"
elif [ $savestat = $netcpy_failed_delete ]
then 
   mail_subject="NETCPY: File deletion FAILED"
else
   mail_subject="NETCPY: UNEXPECTED ERROR"
   # an unexpected error causes the process to go absent
   estatus=$go_absent
fi
#
#
# cleanup
echo $mail_subject
echo $banner
exit $estatus
