Created
May 4, 2021 14:14
-
-
Save minherz/fd9d7b0013b2ac0646ff68307c477201 to your computer and use it in GitHub Desktop.
Wait until startup script logs it is finished with time threshold
This file contains hidden or 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
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