Created
March 15, 2016 22:27
-
-
Save nwgat/baf31fb80647adff9720 to your computer and use it in GitHub Desktop.
simple check if running for service/cron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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