[lug] how to handle open files - upload server
The Matt
thompsma at colorado.edu
Tue Jan 13 10:15:23 MST 2004
On Tue, 2004-01-13 at 09:49, Nate Duehr wrote:
> [Sorry about the cross-post for those on all the lists, just attempting to
> cover a wider audience.]
>
> Here's an interesting one, or maybe I'm just not creative enough today. I
> have a Linux server where people upload some files to me for processing
> (using sftp). The files show up, I move them to another machine to do
> the dirty work. Simple, right? Move those files elsewhere after they
> arrive, which can pretty easily be done from a cron job, no problem
> there.
>
> The case I'm wondering about: How to detect in that regular cron job if
> the file is open (and probably growing) right at the time because it's
> being uploaded right then... so the cron doesn't attempt to move it to
> the other machine in the middle of an upload.
>
> I'm thinking some silly hack at the top of the "move to other machine"
> script that would look at the directory contents with lsof to make sure
> nothing has any of the files to be moved already open. Is there a
> simpler/smarter way?
My first thought was to use lsof or fuser to see if ftp/rcp/scp is using
the file. I doubt this'll work with NFS/automount (locally), but I
don't know.
A quick test shows that scp'ing a file from 1 to 2 shows up in lsof -i
as a 1->2:ssh line. I'd imagine sftp must be similar. Of course, I'm
not a lsof guru so there is probably some nice
"lsof -u jimbo -ac sftp" or something that'll be nicer.
The other ways I can think of are filesize-sleep-filesize checks and
looking for an EOF. I think the lsof is bound to be a more elegant
solution, though.
--
I am a theoretical chemist. Fear me!
Matt Thompson -- http://ucsub.colorado.edu/~thompsma/
440 UCB, Boulder, CO 80309-0440
JILA A510, 303-492-4662
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20040113/311a3dea/attachment.pgp>
More information about the LUG
mailing list