Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

UNIX Scripting FAQ

Tips and Tricks

How do I monitor for a new file is in a directory by gamerland
Posted: 30 Apr 03

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.

#  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)
# mark file with start of day time/date
touch -t $(date +%Y%m%d0000) $TIMESTAMP
until [[ $COMPLETE = "yes" ]]; do
    if [[ $TIMESTAMP -nt $WAITINGON ]]
          sleep 600  # 10 minutes change according to need
...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.

Back to UNIX Scripting FAQ Index
Back to UNIX Scripting Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close