You could use rsync with the --ignore-existing
switch:
skip updating files that exist on receiver
However, I think this is not atomic. You can create advisory locks with flock
to make sure the processes you control (Cooperating processes) won't write to it. But another process still could.
The only way you can lock a file without the risk of a another process messing with it is to mount the filesystem with mandatory locking. From <linux_kernel_source>/Documentation/filesystems/mandatory-locking.txt
:
What is mandatory locking?
Mandatory locking is kernel enforced
file locking, as opposed to the more
usual cooperative file locking used to
guarantee sequential access to files
among processes. File locks are
applied using the flock() and fcntl()
system calls (and the lockf() library
routine which is a wrapper around
fcntl().) It is normally a process'
responsibility to check for locks on a
file it wishes to update, before
applying its own lock, updating the
file and unlocking it again. The most
commonly used example of this (and in
the case of sendmail, the most
troublesome) is access to a user's
mailbox. The mail user agent and the
mail transfer agent must guard against
updating the mailbox at the same time,
and prevent reading the mailbox while
it is being updated.
In a perfect world all processes would
use and honour a cooperative, or
"advisory" locking scheme. However,
the world isn't perfect, and there's a
lot of poorly written code out there.