Skip to content

Instantly share code, notes, and snippets.

@jney
Created November 25, 2010 11:21
Show Gist options
  • Save jney/715232 to your computer and use it in GitHub Desktop.
Save jney/715232 to your computer and use it in GitHub Desktop.
wait_tries.sh
#!/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
#!/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