Skip to content

Instantly share code, notes, and snippets.

@nwgat
Created March 15, 2016 22:27
Show Gist options
  • Select an option

  • Save nwgat/baf31fb80647adff9720 to your computer and use it in GitHub Desktop.

Select an option

Save nwgat/baf31fb80647adff9720 to your computer and use it in GitHub Desktop.
simple check if running for service/cron
#!/bin/bash
# Makes sure we exit if flock fails.
set -e
(
# Wait for lock on /var/program.lock (fd 200) for 10 seconds
flock -n 200
# Do stuff
your program
) 200>/var/program.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment