Usage:

Standard run

 PriceSync

To list files in $dir updated since 201602101230. (If a timestamp is present the job only lists, no FTP.)

PriceSync 201602101230

Setup Instructions for the first run.

The job create a timestamp file in $logdir. When it runs the next time it lists all files newer than the previous timestamp file and FTP’s them from the local pricing server to the other server. In the first run since there is no timestamp file, the job is designed to create a timestamp file and exit. Since we want to sync all files modified after 10th Feb 12:30, we need to create a timestamp file from that date-time, so that when the job run for the first time, it finds a file from that date-time.

rm -f $logdir/PriceSync.TIMESTAMP.*
touch -t yyyymmddHHMM  $logdir/PriceSync.TIMESTAMP.yyyymmddHHMMSS
PriceSync

Script

#!/bin/ksh

############################################################
# PriceSync Program to FTP files
# from current pricing server to the backup pricing server
# Pat Hardikar 09/14/2015 # Created
# Pat Hardikar 09/14/2015 # Modified : Added Debug
############################################################

# Define Variables
export JOBNAME='PriceSync'
export username='USERNAME'
export passwd='PASSWORD'
export MailTo='ABC@EXAMPLE.COM'

if hostname | grep price1
then
        export BACKUP_SERVER='PRIMARY'
        export FromServer='PRIMARY'
        export ToServer='BKP'
else
        export BACKUP_SERVER='BKP'
        export FromServer='BKP'
        export ToServer='PRIMARY'
fi


# Add Files and Directories space delimited
#export dir='/tmp/patz*'
export dir="$I1SCRIPTS $JCLLIB $CARDLIB"

if [[ $# == 1 ]]
then
    if touch -t "$1" /var/tmp/$JOBNAME.TEMP.TIMESTAMP
        then
                # List  Modified Files
                echo "###############################################"
                echo " Displaying files modified after $1  "
                echo "###############################################\n"

                ls -lt `find ${dir} -newer "/var/tmp/$JOBNAME.TEMP.TIMESTAMP"  -type f`
                exit 0
        else
                echo "Invalid TIMESTAMP value: $1. Format must be yyyymmddHHMM" >&2
                exit 1
        fi
else
        ### CONTECT MISSING### 
        done
        echo "close"
        echo "bye"
        } | ftp -in


        # Dump List of file being copied to STDOUT
        echo "\n############ List of Files being FTP'd ############\n"
        printf "%s\n" "${file_list[@]}"
        echo "\n###################################################\n"

        # Send email if any files were synced

        [[ ${#file_list[@]} -gt 1 ]] && {
        echo "The Following files were found recently modified and were synced from $FromServer to $ToServer:\n"
        echo ${file_list[@]}| tr " " "\n" | grep -v "$logdir/PriceSync.TIMESTAMP"
        echo '

        $I1SCRIPTS/PriceSync\n'
        } | mailx -s "PriceSync: Modified Files Synced between $FromServer and $ToServer" $MailTo

        rm "$OldTimeStampFile"

fi