I am not quite sure how effective the test is for date?
Assuming I use the test on my machine for file dummy.txt:
Code:
FILE_DATE="Apr 27" #this is after awk command
SYSTEM_DATE="Apr 27" #as i have run this right now
My issue is that should I run this script at say 1am and have had a file created within the last 10 hours (as per your find)
then I will be moved to the "else" as the dates are not equal??
Wouldn't it be better to check if the files that are less than 10 hours old exist in the ARCHIVE_DIR?
So maybe it could look like:
Code:
#!/bin/bash
#Description: Script to parse incoming file and archive if recent.
DATE=`date +%m-%d-%y`
INBOUND_DIR=/home/dropdir
ARCHIVE_DIR=/home/dropdir/archive
LOG=/home/dropdir/log
#Locate all files that have been placed in directory within last 10 hours.
#cd $INBOUND_DIR #this is not required if your find is already looking there
for FILE in `find $INBOUND_DIR/file* -mmin -600`
do
if [[ ! -e "$ARCHIVE_DIR/${FILE##*/}" ]]; then
echo "Moving received $FILE to archive on $DATE" >> $LOG
mv $FILE $ARCHIVE_DIR
/bin/mail -s "$FILE was recieved on $DATE and archived" me@example.com < /dev/null
else
echo "No file received on $DATE" >> $LOG
/bin/mail -s "$FILE was not received on $DATE and not archived" me@example.com < /dev/null
fi
done
exit