Skip to content

Instantly share code, notes, and snippets.

@whiteley
Created August 12, 2014 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiteley/486b7b2937ad453f18fa to your computer and use it in GitHub Desktop.
Save whiteley/486b7b2937ad453f18fa to your computer and use it in GitHub Desktop.

As part of the cron command

Using flock from the util-linux package.

37 * * * * /usr/bin/flock -n /some/file -c do-something-important-with /some/file

Inside a shell script

Using the programs from the lockfile-progs package.

lockfile-create /some/file
lockfile-touch /some/file &
# Save the PID of the lockfile-touch process
BADGER="$!"
do-something-important-with /some/file
kill "${BADGER}"
lockfile-remove /some/file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment