Hi,

In my thread about automated backup, flock was recommended as a locking solution.

I am trying to get my head around flock, so I am hoping someone can explain.

A typical flock example seems to read as follows:

(
   flock -x -n 200
      if [ $? != "0" ]; then
echo "Unable to obtain exclusive lock. Another backup process is running."
         exit 1
      fi
## Script code here ##

) 200>/data/backups/disk-1.backup.lock

Please correct my assumptions and explain where I am wrong.

1. The brackets ( ) act as a wrapper for the entire script.

2. -The x means exclusive lock is requested.

3. The -n means that the script should fail if an exclusive lock cannot be immediately obtained (versus waiting for a lock).

4. I have no idea what the 200 is. As a blind guess a locking period in seconds or is it an access mode?

5. The "if [ $? != "0" ]" statement tests if there is already an exclusive lock on the file and exits the entire script if there is.

6. The "if ... fi" is the entire locking test and if passed the script code is executed.

7. The last line is part of the wrapper assumed in 1 above, actually creating the lock file using the > redirector. But what is the 200 again?

Kindest Regards

Craig A. Adams


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/4fbd0f7d.7080...@iafrica.com

Reply via email to