Skip to content

Instantly share code, notes, and snippets.

View d-baranowski's full-sized avatar
🎯
Focusing

Dan d-baranowski

🎯
Focusing
View GitHub Profile
############################################
# Instance info
############################################
INSTANCE_ID=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id)
EC2_AVAIL_ZONE=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
REGION="`echo \"$EC2_AVAIL_ZONE\" | /bin/sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
ENI_ID="${ENI_ID}" # have terraform or whatever you're using provide this
ENI_IP=$(/usr/bin/aws ec2 describe-network-interfaces --region=${REGION} | \
/usr/bin/jq -cr --arg i "${ENI_ID}" '.NetworkInterfaces[]|select(.NetworkInterfaceId==$i).PrivateIpAddress')
NETCIDR="${ENI_IP%.*}.0/24" # yeah, it's defaults for my network, put in whatever it is for you
@nickjacob
nickjacob / systemd-prblm.service
Last active March 17, 2023 16:11
execute arbitrary bash code/variable substitution in systemd units
[Unit]
Description=Demonstrate Bash
[Service]
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment MYVAR=$(( 2 + 2 ))"
ExecStart=/usr/bin/echo "2 + 2 = ${MYVAR}"