Created
June 30, 2016 12:29
-
-
Save pahud/1d1a8768d393fc798ec0024fcba59e31 to your computer and use it in GitHub Desktop.
aws-let-me-in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
myip=$(curl -s https://myip.today) | |
sg='sg-XXXXXXXX' | |
ssh_port='4123' | |
aws_ec2_cmd='aws --profile myprofile ec2' | |
open_door(){ | |
echo "=> opening the door for $myip" | |
myip=$1 | |
$aws_ec2_cmd authorize-security-group-ingress --port $ssh_port --cidr $myip/32 \ | |
--protocol tcp --group-id $sg && \ | |
echo "=> door opened" | |
} | |
close_door(){ | |
echo "=> closing the door for $myip" | |
myip=$1 | |
$aws_ec2_cmd revoke-security-group-ingress --port $ssh_port --cidr $myip/32 \ | |
--protocol tcp --group-id $sg && \ | |
echo "=> door closed" | |
} | |
ssh_cmd() { | |
ssh base | |
} | |
open_door $myip && ssh_cmd; | |
close_door $myip | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment