Created
July 4, 2017 05:32
-
-
Save lecoueyl/679a78bd8a34c46f616de45d3a007ac8 to your computer and use it in GitHub Desktop.
AWS ec2 instances hostname ssh completion
This file contains hidden or 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
# | |
# Autocomplete a ssh command with AWS instances hostname | |
# Put this file in /etc/bash_completion.d/ (Ubuntu) | |
# | |
# File containing ec2 instances hostname | |
HOSTS=/tmp/aws_hosts_list | |
_ssh_hosts() | |
{ | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts=$(cat $HOSTS) | |
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) | |
return 0 | |
} | |
complete -F _ssh_hosts ssh |
This file contains hidden or 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
# | |
# List all ec2 instances hostname in a single file every 30 minutes | |
# Note: you need to have AWS Command Line Interface installed | |
# | |
*/30 * * * * zenclerk aws ec2 describe-instances --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]' --output text | tr '\t' '\n' > /tmp/aws_hosts_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The simplest solution I found to complete
ssh
command with the AWS ec2 instance's hostname