<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <tt>Using "touch" and "test -e"</tt> as a lock test is not safe.&nbsp; If
    the shell dies for any reason, the lock file will get stale.<br>
    <br>
    If you sync station is linux, a safer option is to use the flock(1)
    program:<br>
    <br>
    <br>
    <tt><b>NAME<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flock - Manage locks from shell scripts<br>
        <br>
        SYNOPSIS<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flock [-sxon] [-w timeout] lockfile [-c] command...<br>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flock [-sxon] [-w timeout] lockdir [-c] command...<br>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flock [-sxun] [-w timeout] fd<br>
      </b></tt><br>
    <br>
    Here is the lock part of my mirror script:<br>
    <br>
    <b><tt>RunLocked()<br>
        {<br>
        &nbsp;&nbsp; ....<br>
        }<br>
        <br>
      </tt></b><tt><b>(<br>
        &nbsp; flock -w 1 200<br>
        &nbsp; if [ "$?" -ne 0 ] ; then<br>
        &nbsp;&nbsp;&nbsp; echo "Error, lock is already taken..."<br>
        &nbsp;&nbsp;&nbsp; exit<br>
        &nbsp; else<br>
        &nbsp;&nbsp;&nbsp; RunLocked<br>
        &nbsp; fi<br>
        ) 200&gt; ${lockdir}/mirror.centos.lock<br>
        <br>
      </b></tt><br>
    <pre class="moz-signature" cols="72">                                       Jonny

-- 
Jo&atilde;o Carlos Mendes Lu&iacute;s - Computer &amp; Networking Engineer
<a class="moz-txt-link-abbreviated" href="mailto:jonny@jonny.eng.br">jonny@jonny.eng.br</a>
</pre>
    <br>
    On 07/12/2011 11:56 AM, Adam wrote:
    <blockquote cite="mid:4E1C60A6.8020407@gmavt.net" type="cite">admin
      wrote:
      <br>
      <blockquote type="cite">
        <br>
        Yes It would be great . I'm still rsync centos repo.
        <br>
        Could you provide me bash script to rsync with file locking ?
        <br>
      </blockquote>
      <br>
      Attached is a bash locking rsync script.&nbsp; This script is pretty
      informative and intelligent.&nbsp; It verifies that the time stamp of
      the server you are syncing form is newer then yours before it
      syncs.&nbsp; Hence it shouldn't ever delete files you have already
      downloaded if you hit an old mirror.
      <br>
      <br>
      Adam
      <br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
CentOS-mirror mailing list
<a class="moz-txt-link-abbreviated" href="mailto:CentOS-mirror@centos.org">CentOS-mirror@centos.org</a>
<a class="moz-txt-link-freetext" href="http://lists.centos.org/mailman/listinfo/centos-mirror">http://lists.centos.org/mailman/listinfo/centos-mirror</a>
</pre>
    </blockquote>
  </body>
</html>