<!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. 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>
flock - Manage locks from shell scripts<br>
<br>
SYNOPSIS<br>
flock [-sxon] [-w timeout] lockfile [-c] command...<br>
<br>
flock [-sxon] [-w timeout] lockdir [-c] command...<br>
<br>
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>
....<br>
}<br>
<br>
</tt></b><tt><b>(<br>
flock -w 1 200<br>
if [ "$?" -ne 0 ] ; then<br>
echo "Error, lock is already taken..."<br>
exit<br>
else<br>
RunLocked<br>
fi<br>
) 200> ${lockdir}/mirror.centos.lock<br>
<br>
</b></tt><br>
<pre class="moz-signature" cols="72"> Jonny
--
João Carlos Mendes Luís - Computer & 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. 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.
<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>