Skip to content

Instantly share code, notes, and snippets.

@lucien144
Created November 24, 2016 23:30
Show Gist options
  • Save lucien144/9ed86ff105d70f81745aec7687afa083 to your computer and use it in GitHub Desktop.
Save lucien144/9ed86ff105d70f81745aec7687afa083 to your computer and use it in GitHub Desktop.
Atomic shell script for cronjobs
#!/bin/sh
# Author: http://serverfault.com/questions/191083/how-can-i-run-a-script-from-cron-only-once-at-a-time/639747
LOCKDIR=/tmp/.myprog.lock
mkdir $LOCKDIR || exit 0
trap "{ rm -rf $LOCKDIR ; exit 0; }" EXIT
echo "a"
sleep 30
echo "b"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment