I was just following the examples given in the manual, but, indeed, your
suggestion is very good. Thanks a lot!
--
João Carlos Mendes Luís - Computer& Networking Engineer
jonny@jonny.eng.br
On 07/14/2011 08:36 PM, Kealey, Martin, VF-NZ wrote:
>
> Perhaps that example code would clearer if written:
>
> (
> if ! flock -w 1 200 ; then
> echo>&2 "Another process is still running..."
> exit
> fi
> RunLocked
> ) 200> ${lockdir}/mirror.centos.lock
>
> Or
>
> exec 200> ${lockdir}/mirror.centos.lock
> if ! flock -w 1 200 ; then
> echo>&2 "Another process is still running..."
> exit
> fi
> RunLocked
>
> Or for a more succinct version:
>
> ( flock -w 1 200&& RunLocked ) 200> ${lockdir}/mirror.centos.lock
>
> (Point is: referencing "|$?|" is almost never needed, and usually
> obfuscatory.)
>
> *From:*centos-mirror-bounces@centos.org
> [mailto:centos-mirror-bounces@centos.org] *On Behalf Of *João Carlos
> Mendes Luís
> *Sent:* 13 July 2011 03:29
> *To:* Mailing list for CentOS mirrors.
> *Subject:* Re: [CentOS-mirror] I see all your new mirrors ...
>
> Using "touch" and "test -e" as a lock test is not safe. If the shell
> dies for any reason, the lock file will get stale.
>
> If you sync station is linux, a safer option is to use the flock(1)
> program:
>
>
> *NAME**
> flock - Manage locks from shell scripts
>
> SYNOPSIS
> flock [-sxon] [-w timeout] lockfile [-c] command...
>
> flock [-sxon] [-w timeout] lockdir [-c] command...
>
> flock [-sxun] [-w timeout] fd
> *
>
> Here is the lock part of my mirror script:
>
> *RunLocked()**
> {
> ....
> }
>
> (
> flock -w 1 200
> if [ "$?" -ne 0 ] ; then
> echo "Error, lock is already taken..."
> exit
> else
> RunLocked
> fi
> ) 200> ${lockdir}/mirror.centos.lock
>
> *
>
> Jonny
>
> --
> João Carlos Mendes Luís - Computer& Networking Engineer
> jonny@jonny.eng.br
mailto:jonny@jonny.eng.br
>
>
> On 07/12/2011 11:56 AM, Adam wrote:
>
> admin wrote:
>
>
> Yes It would be great . I'm still rsync centos repo.
> Could you provide me bash script to rsync with file locking ?
>
>
> Attached is a bash locking rsync script. This script is pretty
> informative and intelligent. It verifies that the time stamp of the
> server you are syncing form is newer then yours before it syncs.
> Hence it shouldn't ever delete files you have already downloaded if
> you hit an old mirror.
>
> Adam
>
>
>
> _______________________________________________
> CentOS-mirror mailing list
> CentOS-mirror@centos.org
mailto:CentOS-mirror@centos.org
>
http://lists.centos.org/mailman/listinfo/centos-mirror
> ------------------------------------------------------------------------
> Have you seen our website? .... www.vodafone.co.nz
>
http://www.vodafone.co.nz
> Manage Your Account, check your Vodafone Mail and send web2TXT online:
> www.vodafone.co.nz/myvodafone
http://www.vodafone.co.nz/myvodafone
> ------------------------------------------------------------------------
> CAUTION: This correspondence is confidential and intended for the
> named recipient(s) only. If you are not the named recipient and
> receive this correspondence in error, you must not copy, distribute or
> take any action in reliance on it and you should delete it from your
> system and notify the sender immediately. Thank you.
> Unless otherwise stated, any views or opinions expressed are solely
> those of the author and do not represent those of Vodafone New Zealand
> Limited.
> *20 Viaduct Harbour Avenue, Private Bag 92161, Auckland 1030
> Telephone + 64 9 355 2000
> Facsimile + 64 9 355 2001*
> ------------------------------------------------------------------------
> e>
>
>
> _______________________________________________
> CentOS-mirror mailing list
> CentOS-mirror@centos.org
>
http://lists.centos.org/mailman/listinfo/centos-mirror