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

11 lines
309 B
Bash
Raw Normal View History

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