Skip to content

Instantly share code, notes, and snippets.

@minherz
Created May 4, 2021 14:14
Show Gist options
  • Save minherz/fd9d7b0013b2ac0646ff68307c477201 to your computer and use it in GitHub Desktop.
Save minherz/fd9d7b0013b2ac0646ff68307c477201 to your computer and use it in GitHub Desktop.
Wait until startup script logs it is finished with time threshold
wait_startup_script_to_finish() {
vm_name=$1
vm_zone=$2
threshold=$(date --date="-5 min" "+%b %_d %H:%M:%S")
echo -n "Wait for \"$vm_name\" startup script to exit."
status=""
while [[ -z "$status" ]]
do
sleep 3;
echo -n "."
logline=$(gcloud compute ssh $vm_name --zone=$vm_zone --ssh-flag="-q" --command 'tac /var/log/syslog | grep -m 1 "startup-script exit status"' 2>&-)
timestamp=$(echo $logline | awk {print $1,$2,$3})
if [(($threshold - $timestamp)) -gt 0]
then
status=$(echo $logline | awk '{print $NF}')
fi
done
echo ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment