Skip to content

Instantly share code, notes, and snippets.

@sirhopcount
Created December 4, 2018 16:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirhopcount/467ab759a2fd3be80e74d44f065173ec to your computer and use it in GitHub Desktop.
Save sirhopcount/467ab759a2fd3be80e74d44f065173ec to your computer and use it in GitHub Desktop.
AWS ec2 instances hostname ssh completion
#
# 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
#
# 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