There are so many technologies, in so many scripts, it's hard to choose. I'd look at "rsnapshot" which has a decent management of lock files for rsync based mirrors. On Sun, Nov 24, 2013 at 6:54 PM, Rainer Laatsch <[log in to unmask]> wrote: > > On Sat, 23 Nov 2013, Nico Kadel-Garcia wrote: >> >> And a lockfile to prevent multiple copies of your script from piling >> up, especially if you've got this on a cron job > > What is a good method to create a lockfile? The often used primitive > [ -e lockfile ] && return 1; touch lockfile > does not work 100% , as possibly seen by multiply running this script: > > --- snip --- > : > rm lockfile 2>/dev/null > rm lock.result 2>/dev/null > > i=0 > while [ $i -lt 99 ] ; do > > ( > if [ ! -e lockfile ] ; then > touch lockfile > echo "Owner $i" >> lock.result ## believe we are the lock owner > else > echo "Cant lock, $i" >> lock.result ## lockfile is already existing. > fi > ) & > > let i=$i+1 > done > > grep Owner lock.result > count=`grep Owner lock.result | wc -l` ## how many processes think they own the lock? > [ $count -gt 1 ] && echo "BAD lock method [$count] owners" > > --- snip --- > > Regards, R.