<br><br><div class="gmail_quote">On Tue, Nov 3, 2009 at 20:49, Cameron Simpson <span dir="ltr"><<a href="mailto:cs@zip.com.au">cs@zip.com.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="im">On 03Nov2009 13:31, Donald Russell <<a href="mailto:russell.don@gmail.com">russell.don@gmail.com</a>> wrote:<br>
| Another system uses FTP to drop files in a directory for me to process.<br>
| I have a bash script to process the incoming files. The script is started by<br>
| cron periodically.<br>
|<br>
| There's a problem if the FTP transfer is still in progress because the<br>
| process begins reading the file even though it isn't complete yet.<br>
<br>
</div>I liked the upload-then-rename suggested by another poster, if you can<br>
get this implemented.<br>
<br>
Otherwise...<br>
<br>
[...]<br>
<div class="im">| I could also configure the ftp server to lock files being written, but that<br>
| seems to be discouraged. (based on man vsftpd.conf)<br>
<br>
</div>It's not discouraged for any reason that seems to match your use case.<br>
You've got a well defined upload area and no malicious users.<br>
Use the lock facility! That's what it's for!<br>
<div class="im"><br>
| Basically, what I want is something like<br>
| Can I get an exclusive read on file x?<br>
| No - skip that file, go onto the next one<br>
| Yes - start processing that file<br>
<br>
</div>Do it! See above! Have you tried it?<br>
<br>
Cheers,<br><br></blockquote></div><br><br>Thank you all for some great suggestions.... :-)<br><br>Based on the feedback I've received, I'm going to ...<br><br>1 - configure vsftpd to lock files while writing (no malicious users etc)<br>

2 - use ftp put/rename like put ftp-in-progress.foo.bar / rename ftp-in-progress.foo.bar foo.bar because it provides such a great "visual" for watchers, and a convenient way to determine which files are "in transit" and which are complete.<br>

3 - use lockfile/fuser to ensure my cron job doesn't start processing a file that's already being read by an earlier cron job.<br><br>Cheers<br><br><br>