Skip to content

Instantly share code, notes, and snippets.

@joshjdevl
Created March 20, 2015 20:02
Show Gist options
  • Select an option

  • Save joshjdevl/3f900f275b414ffa0429 to your computer and use it in GitHub Desktop.

Select an option

Save joshjdevl/3f900f275b414ffa0429 to your computer and use it in GitHub Desktop.
ec2 tag
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied"
exit -1
fi
#SERVER=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)" --query 'Tags[*].Value' --output text)
SERVER=$1
PRIVATE_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
sudo sed -i "s/^\(HOSTNAME\s*=\s*\).*$/\1$SERVER/" /etc/sysconfig/network
echo "$PRIVATE_IP $SERVER" | sudo tee --append /etc/hosts
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment