* How to lock file from shell?
@ 1999-03-02 5:00 Nikola Milutinovic
1999-03-02 5:00 ` Joe Durusau
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Nikola Milutinovic @ 1999-03-02 5:00 UTC (permalink / raw)
Hi all.
Here is what I would like to do. I'm gonna create several account for in-bound
FTP. User with USER/PASS for those account will be able to leave files on those
account via FTP.
Then I'll create one "pick-up" account. User with that USER/PASS will pick up
files. There will be a cron job, which will transfer files from "in-bound"
accounts to the "pick-up" account.
Well, my problem is: how to detect that the file has been transferred?
The idea of testing a lock on the file, looked promissing, but I have to do it
from a shell script (zsh). "cp" doesn't care if the file is under a
lock/writing. I wouldn't want to implement any kind of "heuristic behavior" - IF
filesize unchanged for past 15 min THEN copy.
Any ideas?
TYIA,
Nix.
--
No flames, send money instead.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 How to lock file from shell? Nikola Milutinovic
@ 1999-03-02 5:00 ` Joe Durusau
1999-03-03 5:00 ` Nikola Milutinovic
1999-03-02 5:00 ` Yvonne & Oliver Maag
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Joe Durusau @ 1999-03-02 5:00 UTC (permalink / raw)
Well, fusers will tell you if a process has the file open. Would that
suffice?
Speaking only for myself,
Joe Durusau
Nikola Milutinovic wrote:
> Hi all.
>
> Here is what I would like to do. I'm gonna create several account for in-bound
> FTP. User with USER/PASS for those account will be able to leave files on those
> account via FTP.
>
> Then I'll create one "pick-up" account. User with that USER/PASS will pick up
> files. There will be a cron job, which will transfer files from "in-bound"
> accounts to the "pick-up" account.
>
> Well, my problem is: how to detect that the file has been transferred?
>
> The idea of testing a lock on the file, looked promissing, but I have to do it
> from a shell script (zsh). "cp" doesn't care if the file is under a
> lock/writing. I wouldn't want to implement any kind of "heuristic behavior" - IF
> filesize unchanged for past 15 min THEN copy.
>
> Any ideas?
>
> TYIA,
> Nix.
> --
> No flames, send money instead.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 How to lock file from shell? Nikola Milutinovic
1999-03-02 5:00 ` Joe Durusau
@ 1999-03-02 5:00 ` Yvonne & Oliver Maag
1999-03-03 5:00 ` Nikola Milutinovic
1999-03-02 5:00 ` Ken Pizzini
1999-03-04 5:00 ` Lars Hecking
3 siblings, 1 reply; 9+ messages in thread
From: Yvonne & Oliver Maag @ 1999-03-02 5:00 UTC (permalink / raw)
If you have an automatic procedure to copy the files via ftp do the
following:
Copy the file with the name x.tmp and after copying rename it in the
ftp program to x
Regards Oliver
On Tue, 02 Mar 1999 11:36:52 +0100, Nikola Milutinovic
<Nikola.Milutinovic@ev.co.yu> wrote:
>Hi all.
>
>Here is what I would like to do. I'm gonna create several account for in-bound
>FTP. User with USER/PASS for those account will be able to leave files on those
>account via FTP.
>
>Then I'll create one "pick-up" account. User with that USER/PASS will pick up
>files. There will be a cron job, which will transfer files from "in-bound"
>accounts to the "pick-up" account.
>
>Well, my problem is: how to detect that the file has been transferred?
>
>The idea of testing a lock on the file, looked promissing, but I have to do it
>from a shell script (zsh). "cp" doesn't care if the file is under a
>lock/writing. I wouldn't want to implement any kind of "heuristic behavior" - IF
>filesize unchanged for past 15 min THEN copy.
>
>Any ideas?
>
>TYIA,
>Nix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 How to lock file from shell? Nikola Milutinovic
1999-03-02 5:00 ` Joe Durusau
1999-03-02 5:00 ` Yvonne & Oliver Maag
@ 1999-03-02 5:00 ` Ken Pizzini
1999-03-03 5:00 ` Nikola Milutinovic
1999-03-04 5:00 ` Lars Hecking
3 siblings, 1 reply; 9+ messages in thread
From: Ken Pizzini @ 1999-03-02 5:00 UTC (permalink / raw)
On Tue, 02 Mar 1999 11:36:52 +0100,
Nikola Milutinovic <Nikola.Milutinovic@ev.co.yu> wrote:
>Then I'll create one "pick-up" account. User with that USER/PASS will pick up
>files. There will be a cron job, which will transfer files from "in-bound"
>accounts to the "pick-up" account.
>
>Well, my problem is: how to detect that the file has been transferred?
...
>The idea of testing a lock on the file, looked promissing, but I have to do it
>from a shell script (zsh). "cp" doesn't care if the file is under a
>lock/writing. I wouldn't want to implement any kind of "heuristic behavior" -
>IF filesize unchanged for past 15 min THEN copy.
1. The best (IMO), if you have control over the client end, is to have
the upload go to a tempfile, and then have the client do a REName
of the tempfile to the final file name when the transfer has completed
sucessfully.
2. The next most promising is the heuristic approach you rejected above.
3. You could check, either via ps or some special mechanism offered by
your particular ftpd, to see that there are no ftp connections active.
Special care must be used to avoid race conditions, probably by
playing games with inter-directory intra-filesystem mv commands.
Only suggestion (1) above is robust (with appropriate controls
on the client end for determining that "the transfer has
completed successfully") against the possibility that a
client might loose their initial ftp connection and then
later complete the file transfer.
--Ken Pizzini
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 ` Joe Durusau
@ 1999-03-03 5:00 ` Nikola Milutinovic
1999-03-03 5:00 ` Joe Durusau
0 siblings, 1 reply; 9+ messages in thread
From: Nikola Milutinovic @ 1999-03-03 5:00 UTC (permalink / raw)
Joe Durusau wrote:
>
> Well, fusers will tell you if a process has the file open. Would that
> suffice?
Sure. Where can I get it?
Nix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-03 5:00 ` Nikola Milutinovic
@ 1999-03-03 5:00 ` Joe Durusau
0 siblings, 0 replies; 9+ messages in thread
From: Joe Durusau @ 1999-03-03 5:00 UTC (permalink / raw)
The 's' was a typo. On my system, (Solaris 2.6) its /usr/sbin/fuser
Try man fuser and see if your system has it.
Speaking only for myself,
Joe Durusau
Nikola Milutinovic wrote:
> Joe Durusau wrote:
> >
> > Well, fusers will tell you if a process has the file open. Would that
> > suffice?
>
> Sure. Where can I get it?
>
> Nix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 ` Yvonne & Oliver Maag
@ 1999-03-03 5:00 ` Nikola Milutinovic
0 siblings, 0 replies; 9+ messages in thread
From: Nikola Milutinovic @ 1999-03-03 5:00 UTC (permalink / raw)
Yvonne & Oliver Maag wrote:
>
> If you have an automatic procedure to copy the files via ftp do the
> following:
> Copy the file with the name x.tmp and after copying rename it in the
> ftp program to x
Well, that's a nice idea, but it doesn't work for me. The people FTP-ing in will
use Windows95 software - FTP Explorer, Rapid FTp, etc.
But a nice idea, though. "mv" should be atomic operation.
Nix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 ` Ken Pizzini
@ 1999-03-03 5:00 ` Nikola Milutinovic
0 siblings, 0 replies; 9+ messages in thread
From: Nikola Milutinovic @ 1999-03-03 5:00 UTC (permalink / raw)
Ken Pizzini wrote:
>
> >Well, my problem is: how to detect that the file has been transferred?
> ...
> >The idea of testing a lock on the file, looked promissing, but I have to do it
> >from a shell script (zsh). "cp" doesn't care if the file is under a
> >lock/writing. I wouldn't want to implement any kind of "heuristic behavior" -
> >IF filesize unchanged for past 15 min THEN copy.
>
> 1. The best (IMO), if you have control over the client end, is to have
> the upload go to a tempfile, and then have the client do a REName
> of the tempfile to the final file name when the transfer has completed
> sucessfully.
I'll try this, but the clients in question are most likely Windows 95 based, FTP
Explorer, Rapid FTP, etc. I'll look into them if they have some scripting
available.
> 2. The next most promising is the heuristic approach you rejected above.
It's problematic, to say the least.
> 3. You could check, either via ps or some special mechanism offered by
> your particular ftpd, to see that there are no ftp connections active.
> Special care must be used to avoid race conditions, probably by
> playing games with inter-directory intra-filesystem mv commands.
Now, this could work. The script "locks on target" and then waits for all FTP
daemons to vanish. Of course, one "zombified" FTP would lock me down. Hmmm.
Stupid Digital FTP daemon clobers itself in "ps -A", gives me this: "-loca
(ftpd)". If I had the complete address... "netstat"? (sigh) It doesn't give the
whole FQDN, just a name without the domain. Then use "-n" and determine in
numeric form...
This pisses me off, which, in turn, tells me there must be an easier way.
> Only suggestion (1) above is robust (with appropriate controls
> on the client end for determining that "the transfer has
> completed successfully") against the possibility that a
> client might loose their initial ftp connection and then
> later complete the file transfer.
I'll see about (1). It really looks robust.
Nix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to lock file from shell?
1999-03-02 5:00 How to lock file from shell? Nikola Milutinovic
` (2 preceding siblings ...)
1999-03-02 5:00 ` Ken Pizzini
@ 1999-03-04 5:00 ` Lars Hecking
3 siblings, 0 replies; 9+ messages in thread
From: Lars Hecking @ 1999-03-04 5:00 UTC (permalink / raw)
Nikola Milutinovic <Nikola.Milutinovic@ev.co.yu> writes:
> Hi all.
>
> Here is what I would like to do. I'm gonna create several account for in-bound
> FTP. User with USER/PASS for those account will be able to leave files on those
> account via FTP.
>
> Then I'll create one "pick-up" account. User with that USER/PASS will pick up
> files. There will be a cron job, which will transfer files from "in-bound"
> accounts to the "pick-up" account.
>
> Well, my problem is: how to detect that the file has been transferred?
>
> The idea of testing a lock on the file, looked promissing, but I have to do it
> from a shell script (zsh). "cp" doesn't care if the file is under a
> lock/writing. I wouldn't want to implement any kind of "heuristic behavior" - IF
> filesize unchanged for past 15 min THEN copy.
>
> Any ideas?
A tool called lockfile comes with procmail. Maybe this is what you're
looking for?
NAME
lockfile - conditional semaphore-file creator
SYNOPSIS
lockfile -sleeptime | -r retries |
-l locktimeout | -s suspend | -! | -ml | -mu | filename
...
...
EXAMPLES
Suppose you want to make sure that access to the file
"important" is serialised, i.e. no more than one program or
shell script should be allowed to access it. For
simplicity's sake, let's suppose that it is a shell script.
In this case you could solve it like this:
...
lockfile important.lock
...
access_"important"_to_your_hearts_content
...
rm -f important.lock
...
Now if all the scripts that access "important" follow this
guideline, you will be assured that at most one script will
be executing between the `lockfile' and the `rm' commands.
...
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1999-03-04 5:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-03-02 5:00 How to lock file from shell? Nikola Milutinovic
1999-03-02 5:00 ` Joe Durusau
1999-03-03 5:00 ` Nikola Milutinovic
1999-03-03 5:00 ` Joe Durusau
1999-03-02 5:00 ` Yvonne & Oliver Maag
1999-03-03 5:00 ` Nikola Milutinovic
1999-03-02 5:00 ` Ken Pizzini
1999-03-03 5:00 ` Nikola Milutinovic
1999-03-04 5:00 ` Lars Hecking
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox