Created
July 29, 2016 01:20
-
-
Save cliffano/cae9c30c660714a5e53b6068a55780a9 to your computer and use it in GitHub Desktop.
wait for the existence of a facter fact via shell
This file contains 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 | |
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