Elastic IPが紐づいているか確認してからassosiateするシェルスクリプト

EC2_IP=XX.XXX.XXX.XXX
PUBLIC_DNS=`curl -q http://169.254.169.254/latest/meta-data/public-hostname`
INSTANCE_ID=`curl -q http://169.254.169.254/latest/meta-data/instance-id`
ALLOCATED_ID=`ec2-describe-addresses | grep ${EC2_IP} | sed "s/s+/ /g" | cut -f3 -d' '`

echo ""
if [ "${INSTANCE_ID}" = ${ALLOCATED_ID} ]; then
  echo "IP ${EC2_IP} already assosiated to this instance ${INSTANCE_ID}"
else
  echo "IP-Address: ${EC2_IP}"
  echo "Currently assosiated instance: ${ALLOCATED_ID}"
  echo "Current URL for this instance: ${PUBLIC_DNS}"
  echo "Are you sure you change Ip assosiated to ${INSTANCE_ID} ? (yes/no)"
  read yn
  if [ "${yn}" != "yes" ]; then
    echo "Assosiate canceled"
    exit 0;
  fi
  ec2-associate-address -i ${INSTANCE_ID} ${EC2_IP}
fi