Using a shell script, I'm looking to get the current AZ where the instance is located.
Here is what I've tried but obviously HOST_NAME is not a command. How do I save the current AZ in a HOST_NAME variable?
AZ=`ec2-metadata -z | cut -d':' -f2`
if [[ $AZ = "eu-west-2a" ]]
then
HOST_NAME = "es_az1"
elif [[ $AZ = "eu-west-2b" ]]
then
HOST_NAME = "es_az2"
else
HOST_NAME = "es_az3"
exit 1;
fi
CodePudding user response:
You can't have spaces in HOST_NAME =
. It should eb:
AZ=`ec2-metadata -z | cut -d':' -f2`
if [[ $AZ = "eu-west-2a" ]]
then
HOST_NAME="es_az1"
elif [[ $AZ = "eu-west-2b" ]]
then
HOST_NAME="es_az2"
else
HOST_NAME="es_az3"
exit 1;
fi