Skip to content

Instantly share code, notes, and snippets.

@closer
Forked from threetreeslight/ec2-ssh.sh
Last active August 29, 2015 14:06
Show Gist options
  • Save closer/9769aa683a612a3c19d8 to your computer and use it in GitHub Desktop.
Save closer/9769aa683a612a3c19d8 to your computer and use it in GitHub Desktop.
# ec2-ip
function ec2-ip() {
instances | percol | awk '{ print $1 }'
}
function instances() {
instances=( $(aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value[],PublicIpAddress]' \
--output text \
--profile `aws-profile | percol`) )
for i in `seq 1 ${#instances[@]}`; do
if [ `expr $i % 2` -eq 0 ]; then
echo ${instances[$i-1]} ${instances[$i]}
fi
done
}
function aws-profile() {
cat ~/.aws/config | sed -e "/^[^\[]/d" -e "s/^\[profile \(.*\)\]$/\1/g"
}
# ec2-ssh
function ec2-ssh() {
mosh webadmin@`ec2-ip` --ssh="ssh -p 2222 -i ~/.ssh/id_rsa"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment