Skip to content

Instantly share code, notes, and snippets.

@aguy
aguy / gist:dd9646eba1e4aebec5f1
Last active December 29, 2016 12:39
ec2 rename from tag
#!/bin/bash
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
FQDN=$(aws ec2 describe-tags --region $REGION --filters "Name=resource-id,Values=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" "Name=key,Values=Name" --query Tags[].Value --output text)
HOSTNAME=$(echo $FQDN | cut -d. -f1)
IPADDRESS=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
if [ -z "$HOSTNAME" ]; then
echo "You forgot to set Hostname in Tag Name."
exit 0
@aguy
aguy / include.sh
Created April 11, 2012 14:49
shell script trap functions
#!/bin/bash
set -o errexit # exit on errors
set -o nounset # exit on use of uninitialized variable
set -o errtrace # inherits trap on ERR in function and subshell
trap 'traperror $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]:-})' ERR
trap 'trapexit $? $LINENO' EXIT
function trapexit() {