code-dumps/aws/list-unused-sg.sh

11 lines
309 B
Bash
Executable File

#!/bin/bash
TMPFILE=/dev/shm/enisg.lst
aws ec2 describe-network-interfaces --query NetworkInterfaces[].Groups --output text > $TMPFILE
for sg in $(aws ec2 describe-security-groups --query 'SecurityGroups[*].GroupId' --output text); do
echo -n "$sg : "
grep -c $sg $TMPFILE
done | sort -k3 -n
rm -f $TMPFILE