Home > Enterprise >  Getting line 19: syntax error: unexpected end of file
Getting line 19: syntax error: unexpected end of file

Time:12-01

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




CodePudding user response:

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

  • Related