Flag file management techniques using rsync

Wayne Davison wayned at samba.org
Mon Nov 8 16:23:37 GMT 2004

On Sun, Nov 07, 2004 at 10:54:56PM +1100, Frank Hamersley wrote:
> I am looking for a way to check for (or duplicate) single flag files
> to and from a remote host (without any dummy spit errors when it is
> not present) and ideally avoiding the need for a specialised sub
> directory for each flag file.

For such a simple operation, you should be just using ssh (or rsh) to
run simple shell commands, such as "touch" and "rm".  Certainly rsync
could be used, and the mailing list has just recently explained twice
now how to delete an individual file using rsync (for those times that
a remote shell is not involved), but since you're using a remote shell,
you should use it to run the necessary shell commands:

    ssh -l rmtusr rmthost.net touch /somepath/file1.flg
    ssh -l rmtusr rmthost.net rm /somepath/file1.flg
    ssh -l rmtusr rmthost.net test -e /somepath/file1.flg

You can use the last command to cache the file1.flg locally if you need
to test it more than once (or just use the result if you don't).  Keep
in mind that on failure you'll probably want to distinguish between the
file not being there (error return 1) and the remote connection not
working (error return 255).

Also, if multiple processes are all competing for the same lock file,
you'll want to replace the touch with a script/program on the remote
host that does an atomic locking operation that only lets one process
acquire the lock (sleeping or returning failure, as appropriate).


More information about the rsync mailing list