Skip to content

Instantly share code, notes, and snippets.

@cliffano
Created July 29, 2016 01:20
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 cliffano/cae9c30c660714a5e53b6068a55780a9 to your computer and use it in GitHub Desktop.
Save cliffano/cae9c30c660714a5e53b6068a55780a9 to your computer and use it in GitHub Desktop.
wait for the existence of a facter fact via shell
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: check-fact <fact_name>" >&2
exit 1
fi
name=${1}
max_retries=60
delay=5 # second(s)
counter=1
while [ ${counter} -le ${max_retries} ]; do
value=`facter ${name}`
if [ -z "${value}" ] && [[ ! -e "${value}" ]]; then
echo "Check #${counter} - fact ${name} not found"
else
echo "Check #${counter} - fact ${name} found"
exit 0
fi
sleep ${delay}
counter=$(( counter+1 ))
done
echo "Exiting due to ${name} variable not found after ${counter} checks with ${delay} sec(s) interval..."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment