Option 1:
This watches for a new file to show up after "touch time"
and move it to the archive. See grep for all the -exec options.
#!/bin/ksh
#
TIMESTAMP="[color blue]YourPathAndFilenameToTimestampFile[/color]"
FILENAME="[color blue]YourPathAndFilenameHere[/color]"
ARCHIVE="[color blue]YourArchivePathAndNameHere[/color]"
# Set touch date to current date (and time if you need)
touch -t $(date +%Y%m%d0000) $TIMESTAMP
find $FILENAME -newer $TIMESTAMP -exec cp $FILENAME $ARCHIVE {} \;
If you are waiting for a file to arrive so you can do something else. Perhaps you get a file every "X" hours and but it is not scheduled. A file could arrive at 11:00 and 13:00 or 11:00, 12:00 and 12:40.
Option 2:
However if the real issue is waiting for the ftp file to show up, try this: (Korn shell)
#
#!/bin/ksh
#
TIMESTAMP="[color blue]YourPathAndFilenameToTimestampFile[/color]"
WAITINGON="/home/ftpfile"
#
# mark file with start of day time/date
touch -t $(date +%Y%m%d0000) $TIMESTAMP
#
COMPLETE="no"
until [[ $COMPLETE = "yes" ]]; do
if [[ $TIMESTAMP -nt $WAITINGON ]]
then
sleep 600 # 10 minutes [color blue]change according to need[/color]
else
COMPLETE="yes"
fi
done
...remainder of process here.
This way you will start the process and if your file is not there yet, sleep and look again. Once it gets there, off you go. I strongly suggest you put an extra check in that if the file does not show up in a given amount of time it sends an alert/email/notice/etc.
This would be put into cron to run on a schedule near arrival time for the file. It will wait from there.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.