Skip to content

Instantly share code, notes, and snippets.

@tkellen
Created April 2, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkellen/e0f81125953b86c39038 to your computer and use it in GitHub Desktop.
Save tkellen/e0f81125953b86c39038 to your computer and use it in GitHub Desktop.
poll for something and exit when good
#!/bin/bash
POLL_INTERVAL=1
TIMEOUT_COUNT=5
COUNTER=1
FILE="stop.txt"
printf "waiting for stop.txt to appear"
while true; do
if [ $COUNTER -gt $TIMEOUT_COUNT ]
then
echo "too slow"
exit 1
fi
if [ -f $FILE ]
then
echo "!"
echo "ready"
exit 0
else
printf "."
sleep $POLL_INTERVAL
COUNTER=$[$COUNTER +1]
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment