Created
November 25, 2010 11:21
-
-
Save jney/715232 to your computer and use it in GitHub Desktop.
wait_tries.sh
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 | |
LOCK_FILE="pgr.lock" | |
MAX_TRIES=5 | |
if [[ -f $LOCK_FILE ]]; then | |
TRIES=$((`cat $LOCK_FILE` + 1)) | |
echo $TRIES > $LOCK_FILE | |
if [[ $TRIES < $MAX_TRIES ]]; then | |
echo "already running, let's try later" | |
else | |
echo "we waited too long, let's raise an error" | |
fi | |
fi |
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 | |
LOCK_FILE="pgr.lock" | |
MAX_WAIT=$((10 * 60)) # wait 10 minutes | |
if [[ -f $LOCK_FILE ]]; then | |
UPDATED_IN_SECONDS=$((`date +%s` - `stat -c %Y $LOCK_FILE`)) | |
if [[ $UPDATED_IN_SECONDS < $MAX_WAIT ]]; then | |
echo "already running, let's try later" | |
else | |
echo "we waited too long, let's raise an error" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment