AnotherAlan
Technical User
Morning All,
I have a requirement to copy files from a source dir to a destination dir based on the following criteria;
The source files cannot be changed / modified or moved and will hold 7 days worth of data. These files are application generated and can be created at any time of day.
The destination directory should only contain files that have not yet been copied from the source directory.
Files in here will be picked up and then deleted by another application.
My logic is to create the above scenario by using a logfile to monitor which files have been copied and to compare all new files in the source dir against this log prior to copying to the destination directory. Hope this makes sense.
Anyhow, I have written the below ksh script that does the job. It's not pretty but it works. However, as I have been trying to learn AWK for a number of years now (with limited success obviously) I am keen to know of a way to do this.
I'm also open to any suggestions on the logic I have used.
I'm not a programmer, just a lowly Admin, hence the more than likely poor choice.
#!/bin/ksh
# Declare Variables
COPY_LOG=TEST/copy_log.`date +%b-%e-%T`
SOURCE_DIR=TEST/test_source
SOURCE_DIR_LOG=TEST/test_source.log
DEST_DIR=TEST/test_dest
CHECK_LOG=TEST/check_log
FILES_2_COPY=TEST/files_2_copy.log
exec > $COPY_LOG 2>&1
# Grab list of cpty files from Source
ls -1 $SOURCE_DIR | grep cpty* > $SOURCE_DIR_LOG
# Compare source files against check log - create log of files to copy
[ -f $FILES_2_COPY ] && rm $FILES_2_COPY
fgrep -v -f $CHECK_LOG $SOURCE_DIR_LOG > $FILES_2_COPY
# Copy files in FILES_2_COPY to Destination directory
echo "Files copied to TEST_DEST directory"
while read filename; do
echo $filename
cp -p $SOURCE_DIR/$filename $DEST_DIR && echo $filename >> $CHECK_LOG
done < $FILES_2_COPY
Many thanks all
I have a requirement to copy files from a source dir to a destination dir based on the following criteria;
The source files cannot be changed / modified or moved and will hold 7 days worth of data. These files are application generated and can be created at any time of day.
The destination directory should only contain files that have not yet been copied from the source directory.
Files in here will be picked up and then deleted by another application.
My logic is to create the above scenario by using a logfile to monitor which files have been copied and to compare all new files in the source dir against this log prior to copying to the destination directory. Hope this makes sense.
Anyhow, I have written the below ksh script that does the job. It's not pretty but it works. However, as I have been trying to learn AWK for a number of years now (with limited success obviously) I am keen to know of a way to do this.
I'm also open to any suggestions on the logic I have used.
I'm not a programmer, just a lowly Admin, hence the more than likely poor choice.
#!/bin/ksh
# Declare Variables
COPY_LOG=TEST/copy_log.`date +%b-%e-%T`
SOURCE_DIR=TEST/test_source
SOURCE_DIR_LOG=TEST/test_source.log
DEST_DIR=TEST/test_dest
CHECK_LOG=TEST/check_log
FILES_2_COPY=TEST/files_2_copy.log
exec > $COPY_LOG 2>&1
# Grab list of cpty files from Source
ls -1 $SOURCE_DIR | grep cpty* > $SOURCE_DIR_LOG
# Compare source files against check log - create log of files to copy
[ -f $FILES_2_COPY ] && rm $FILES_2_COPY
fgrep -v -f $CHECK_LOG $SOURCE_DIR_LOG > $FILES_2_COPY
# Copy files in FILES_2_COPY to Destination directory
echo "Files copied to TEST_DEST directory"
while read filename; do
echo $filename
cp -p $SOURCE_DIR/$filename $DEST_DIR && echo $filename >> $CHECK_LOG
done < $FILES_2_COPY
Many thanks all