in reply to lock files vs. non-predictable file names

Don't use /tmp for sentinel files like this. Create a directory writable only by the user running this crontab, and put the file in there. Then you won't have to worry about someone deleting your file.

Also, replace system touch.. with just

open DUH, ">/tmp/some.file"; close DUH;
No separate process required that way. Better security. Ditto with unlink instead of system rm.

And, you really don't want to use a sentinel file like that. See my Highlander - allow only one invocation at a time of an expensive CGI script as a model to use flock with a sentinel file.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE (tilly) 2: lock files vs. non-predictable file names
by tilly (Archbishop) on Aug 26, 2000 at 01:23 UTC
    Actually ">>/tmp/some.file" is better.

    Opening the file by writing to it can lead to issues of people, waiting for your process to start, then placing a symlink to another file. It isn't easy and there is definitely an element of luck, but keep trying and you will hit it eventually. So create with an append, then test for the symlink if you are paranoid.

    Incidentally another model to look at for sentinal files is Simple Locking.

      I was wondering about that (">" vs. ">>"). I actually got to learn about the symbolic link problem in /tmp through someone else's misfortune. Thanks for the link on Simple locking too.
RE: Re: lock files vs. non-predictable file names
by RuphSkunk (Acolyte) on Aug 26, 2000 at 01:23 UTC
    Thanks for advice on the private directory...and the replacements for the system calls. I think I'll devote some time to grok highlander...ty.