Skip to content

Instantly share code, notes, and snippets.

@denoww
Created March 30, 2021 14:27
Show Gist options
  • Save denoww/ff9e4092bbd52561029a37a8157cc7c2 to your computer and use it in GitHub Desktop.
Save denoww/ff9e4092bbd52561029a37a8157cc7c2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# cx stacks list
# cx servers list -s stacks.name
has_cx_command="$(command -v cx)"
if [ $has_cx_command ]; then
stacks_list="$(cx stacks list | grep -P '^(?!NAME)' | grep -Eo '^\S*')"
for stack in $stacks_list; do
echo "=========== stack '$stack' ==========="
name_serv=$(echo "$stack" | sed 's/seucondominio_//' | sed 's/_.*$//')
servers_list="$(cx servers list -s $stack | grep -Eo '^\S*')"
for server in $servers_list; do
echo "=========== server '$server' ==========="
numb_serv=$(echo "$server" | rev | cut -c1 | tr -dc '0-9')
if [ "$numb_serv" == "" ]; then
numb_serv=$server
name_serv=""
fi
if [ "$numb_serv" == "1" ]; then
alias_name="sc$name_serv"
alias_command="cx ssh -s '$stack' -e production '$server'"
echo "Creating alias: $alias_name=$alias_command"
fi
alias_name="sc$name_serv$numb_serv"
alias_command="cx ssh -s '$stack' -e production '$server'"
echo "Creating alias: $alias_name=$alias_command"
# alias $alias_name="$alias_command"
done
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment