Skip to content

Instantly share code, notes, and snippets.

@Stilg4r
Created June 15, 2020 19:55
Show Gist options
  • Save Stilg4r/fca0c1399ec4bef1e7246af1e2d08490 to your computer and use it in GitHub Desktop.
Save Stilg4r/fca0c1399ec4bef1e7246af1e2d08490 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Este scrip agrega la ip publica a un grupo de seguridad de aws,
# guarda la ultmia ip que se se agrego en un archivo
# si el archivo exste intenta eleminar la ip del grupo de seguridad
# si la ip es la misma que el archivo no hace nada
GROUPID="";
PROTOCOL="";
PORT="";
FILE="awsip";
if [ -z "$1" ] && [ -z "$2" ];
then
IP="$(curl -s checkip.amazonaws.com)";
else
FILE=FILE$2;
IP=$1;
fi
echo "Usando la ip: $IP";
echo "Usando el archivo: $FILE";
if test -f "$FILE";
then
OLDIP="$(cat $FILE)";
if [ "$IP" = "$OLDIP" ]; then
echo "Es la misma ip que $OLDIP";
exit;
fi
echo "Borrando la ip";
aws ec2 revoke-security-group-ingress --group-id $GROUPID --protocol $PROTOCOL --port $PORT --cidr $OLDIP/32;
fi
echo "Guardando la ip";
echo $IP >| $FILE;
echo "Autrizando";
aws ec2 authorize-security-group-ingress --group-id $GROUPID --protocol $PROTOCOL --port $PORT --cidr $IP/32;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment