Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write a script to find new files in a directory?

Status
Not open for further replies.

tbtcust

Programmer
Oct 26, 2004
214
US

Hello everyone. I am brand new to UNIX and need write a script that will run every ten mins. The script will look at a directory full of files that have been FTPed to it. The logic will be:
1) Look at a directory for new files that have an extension of ".send"
2) If there are new ".send" files, email the file names only to an email address
3) Do nothing if there are no new ".send" files

Is this possible? How would I code this in a script?

Thanks in advance for any help
 
man cron
man touch
man find
man sendmail

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
When we do this sort of operation at my installation, we generally rename each file as we process it (e.g. rename whatever.send to whatever.sent). You don't have to do that, but for us, it makes it obvious which files were processed.

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
While I somewhat agree with previous comments - one should read the man pages - sometimes that is just not enough... an actual example is needed to flick on that light of comprehension.

We have a script that does something similar to what you are asking:

Code:
SRC="/some/place"
DST="/some/other/place/"

cd $SRC
find . ! -name . -prune -type f -mmin -1 -exec cp {} $DST \;

What the above does is:
- define the source and destination directories
- change to the source directory
- look for all files that are new in the past minute - in this directory only, no subdirs
- if new files found, copy to destination location.

Apply your requirements to the above logic and update/modify as needed to obtain your desired results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top