Need a script to copy files and check

Hi all,

I need a script in ksh:

1: Copy files from directory (A) to directory (B)
2: Check if files that will be copied in directory (A) have never been yet copied to (B)
3: Never copy the last created file of directory (A)

This script will run on crontab.

Thanks in advance for your help

To start with try this....

#!/bin/bash -x


NUFILELIST1="/tmp/testfile1"

NUFILELIST2="/tmp/testfile2"

DIR1="/your/home/directory"

DIR2="/your/copy/directory"



cd $DIR1

ls -1 > $NUFILELIST1

var="`ls -lrt | tail -1 | awk '{print $9}'`"

echo $var

sed '/'$var'/d' $NUFILELIST1  > /tmp/testfile2

cd $DIR2

for x in `cat /tmp/testfile2`
do
        if [ -f $x ]; then

                echo "Duplicate file $x"
        else
                cp $DIR1/$x $DIR2
        fi
done

rm $NUFILELIST1

rm $NUFILELIST2

exit 0