I know how to use lock files, Kenneth. I've been writing software for
UNIX for 30 years.
Lock files aren't enforced on Linux, they're advisory. Everybody
accessing the resource protected by the lock has to use the same locking
protocol for it to do any good. In this case, the race condition we're
talking about is between two different scripts, one of which I don't
maintain. It would do me zero good to use a lock file in my script if
the other script isn't using it as well.
jik
On 04/14/2017 01:16 PM, Kenneth Porter wrote:
> --On Thursday, April 13, 2017 12:18 PM -0400 Jonathan Kamens
> <j...@kamens.us> wrote:
>
>> However, there is a race condition risk: since my script runs
>> continuously and adds new IPs to hosts.deny as they are detected, it
>> could end up trying to update hosts.deny at the same time as the other
>> script. Both my script and the other one make their changes by creating
>> a new version of hosts.deny and then renaming it into place, so
>> hosts.deny will never end up getting corrupted; the worst that could
>> happen is that an update from one of the two scripts could be lost.
> man flock
>
> Try something like this in your script:
>
> # only allow one copy of script in here at a time
> ME=`basename "$0"`;
> LCK="${HOME}/${ME}.LCK";
> exec 8>$LCK;
> flock -x 8;
>
> You'll want to adjust the name and location of the lock file, of course.
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Fail2ban-users mailing list
> Fail2ban-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fail2ban-users
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Fail2ban-users mailing list
Fail2ban-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fail2ban-users