![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How Can I Easily Determine If A File Has been Added to a Directory | goodmis | UNIX for Dummies Questions & Answers | 1 | 01-31-2007 06:56 PM |
| cannot determine current directory | axes | UNIX for Advanced & Expert Users | 15 | 11-13-2006 07:39 AM |
| determine owner directory permissions from within the directory | Sniper Pixie | Shell Programming and Scripting | 4 | 03-07-2006 05:06 PM |
| How to generate a configuration file easily and effectively? | sarathytcs | Shell Programming and Scripting | 0 | 01-30-2006 09:51 AM |
| How to scan only new lines added in file? | redlotus72 | UNIX for Dummies Questions & Answers | 3 | 04-28-2005 04:34 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How Can I Easily Determine If A File Has been Added to a Directory
I am uploading files that need to be processed prior to uploading. I will put the files in a directory. My question is how can I write an easy process to kick off a script once a file has been added? Is there an easy way to determine if a file has been added to a directory?
Thanks |
|
||||
|
At the end of you script create a file in the same directory with a name you like.
At the start of your script search for files which are newer than the file you created in your previous run. script: ------------------------------------------------------------------- #!/usr/bin/ksh cd /somedir for FILE in `find ./* -prune -type f -newer ./TIMEFILE` do # do whatever you wanna do with the new files. done touch ./TIMEFILE ------------------------------------------------------------------- if you want to include subdirectories as well replace find ./* -prune -type f -newer ./TIMEFILE by find . -type f -newer ./TIMEFILE The touch command makes sure the file TIMEFILE always has a timestamp of when the last run of your script ended. The find command will find only find files which have been place in the directory of the timestamp time of TIMEFILE |
|
||||
|
Quote:
Instead of touch ./TIMEFILE you use date > ./TIMEFILE At the beginning of the script something like: OLDDATE=`cat ./TIMEFILE` |
|
||||
|
I was told to run a cron job every 2 minutes and once it found the file I could have it transfer it. It seems like overkill to have a process running every 2 minutes looking for a file that may be added only once a day.
Thanks to all who answered |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|