#!/bin/csh
#------------------------------------------------------------------------
#                          REVISION HISTORY                             -
#                                                                       -
#------------------------------------------------------------------------
#  MOD            PR                                                    -
# LEVEL   DATE   NUMBER  USER     DESCRIPTION
# ----- -------- ------  -------  ------------------------------------  -
#  000  10/23/01 44668   J.Baum  Initial version - derived from ht_copy
#       06/19/10 65423   MSwam   changes for SFTP
#------------------------------------------------------------------------
#
# Module:	save_copy.csh
#
#------------------------------------------------------------------------
# DESCRIPTION:
#
#  This script uses netcopy to copy files from the FOF pipeline to a
#  specified remote directory used by the Engineering Team (ET). It is
#  designed to be run in the FOF pipeline.
#
#  Required variables from resource file: 
#        RMT_MACHINE        host for remote directory
#        RMT_MACHINE_TYPE   VMS or UNIX
#        RMT_LOGIN          login account name
#        RMT_DIR            remote directory
#        INPATH             local directory
#        EXTENSION          save file extension
#
#*********************************************************************
#
set go_absent = 102          #this exit status is in the FATAL range for XPOLL
set netcpy_no_files = 5      #No files found
set netcpy_success = 3       #netcopy succeeded
set osf_success = 0
set osf_failure = 1
#
echo -n `\date +"%Y%j%H%M%S"`
echo "-I-INFO - processing OSF $OSF_DATASET."
#
# Construct local file mask and perform copy.
# The sed substitution pattern strips the first 3 characters off OSF_DATASET.
# Use noglob to avoid file matching while setting spec_mask.
set noglob
set spec_mask = ${INPATH}/`echo $OSF_DATASET | sed "s/^...\(.*\)/\*\1/"`
set spec_mask = $spec_mask$EXTENSION
unset noglob
#
echo -n `\date +"%Y%j%H%M%S"`
echo "-I-INFO Copying $spec_mask"
netcopy -rm $RMT_MACHINE -rl $RMT_LOGIN -lf "$spec_mask" -rf $RMT_DIR -pg PUT  
set estatus = $status
if ($estatus != $netcpy_success) then
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-E-ERROR netcopy failed (exit status = $estatus)."
   exit $osf_failure
else
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-I-INFO netcopy successful for OSF $OSF_DATASET."
   exit $osf_success
endif
