Skip to content

Instantly share code, notes, and snippets.

@brianbianco
Created August 16, 2012 15:24
Show Gist options
  • Save brianbianco/3371019 to your computer and use it in GitHub Desktop.
Save brianbianco/3371019 to your computer and use it in GitHub Desktop.
#!/bin/bash
#Author: Brian Bianco
#Email: Brian.Bianco@gmail.com
usage()
{
cat << EOF
usage: $0 options
OPTIONS:
-h Show this message
-a Show all instance info
-m <meta-data name> will return the value of that meta-data
EOF
}
if [ $# -eq 0 ]; then
usage
exit 1;
fi
ALL=
META_NAME=
while getopts "hvam:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
a)
ALL=1
;;
m)
META_NAME=$OPTARG
;;
?)
usage
exit 1
;;
*)
usage
exit 1
;;
esac
done
info=('ami-id' 'ami-launch-index' 'ami-manifest-path' 'ancestor-ami-ids' 'hostname' 'instance-action' 'instance-id' 'instance-type' 'kernel-id' 'ramdisk-id' 'local-hostname' 'local-ipv4' 'mac' 'profile' 'public-hostname' 'public-ipv4' 'reservation-id' 'security-groups' 'public-keys' 'block-device-mapping/ami' 'block-device-mapping/ephemeral0' 'block-device-mapping/root' 'placement/availability-zone' 'network/interfaces/macs');
if [ ! -z $META_NAME ]; then
wget -qO- http://169.254.169.254/latest/meta-data/${META_NAME}
echo
fi
if [ ! -z $ALL ]; then
for info in ${info[@]}
do
echo -n "${info} : "
wget -qO- http://169.254.169.254/latest/meta-data/${info}
echo
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment