简体   繁体   中英

Getting line 19: syntax error: unexpected end of file

I'm trying to associate the Elastic IP address with Auto scaling group, so whenever the autoscaling triggers it will automatically associate with the EIP.

For this I'm trying to add the script in user data.

My intention is to we have 2 servers so its associated with 2 EIP's, whenever the autoscaling triggers it has to check whether the EIP is free or not if its free it has to associate with that instance using the instance id.

So when i run the script im getting line 19: syntax error: unexpected end of file. I have checked the indentations but i think its correct.

#!/bin/bash
INSTANCE_ID=$(ec2-metadata --instance-id | cut -d " " -f 2);
EIP_LIST=(eipalloc-07da69856432f7cef eipalloc-0355263fcb50412ed)
for EIP in $${EIP_LIST}; do
        echo"Checkin if EIP is free"
        ISFREE=$(aws ec2 describe-addresses --allocation-ids $EIP --query Addresses[].InstanceID --output text --region ap-south-1)
        STARTWAIT=$(date +%s)
        while [ ! -z "$ISFREE" ]; do
                if [ "$(($(date +%s) - $STARTWAIT))" -gt $MAXWAIT ]; then
                        echo "WARNING: We waited for 30 seconds, we are forcing it now."
                        ISFREE=""
                else
                        echo "checking the other EIP [$EIP]"
                        ISFREE=$(aws ec2 describe-adresses --allocation-ids $EIP --query Addresses[].InstanceID --output text --region ap-south-1)
                fi
        done
        echo "Running: aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $EIP --allow-reassociation --region ap-south-1"
        aws ec2 association-address --instance-id $INSTANCE_ID --allocation-id $EIP --allow-reassociation --region ap-south-1




You are missing the final done for the for -loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM