Bash To The Rescue: Quick SSH Selector for CodexMCP Stack

Right now, as I do a lot of active dev on CodexMCP, I’m constantly rebuilding VMs, tweaking configs, testing individual services. That means I’m SSH’ing into these VMs all the time, often dozens of times a day.

I wanted a simple way to SSH into any VM in the project, no looking up IPs, no having to type hostnames.

For now, this little script does the job:

#!/bin/bash

# Define the directory containing YAML files
YAML_DIR="livelaunchers"

# Initialize an empty list
VM_LIST=""

# Loop over all YAML files in the directory
for yaml_file in "$YAML_DIR"/*.yml; do
    # Only process if file exists and not empty
    if [[ -s "$yaml_file" ]]; then
        VM_LIST+=$(awk '
            /name:/ {gsub(/[""]/, "", $2); name=$2}
            /ipaddress:/ {gsub(/[""]/, "", $2); ip=$2; print name, ip}
        ' "$yaml_file")
        VM_LIST+=$'\n'
    fi
done

# Remove any trailing newline
VM_LIST=$(echo "$VM_LIST" | sed '/^$/d')

# Convert to array for indexing
IFS=$'\n' read -rd '' -a VM_ARRAY <<< "$VM_LIST"

# Display Menu
echo "Select a VM to SSH into:"
for i in "${!VM_ARRAY[@]}"; do
    echo "$((i+1))) ${VM_ARRAY[i]}"
done

# Get user selection
read -p "Enter selection: " choice
if [[ "$choice" -gt 0 && "$choice" -le "${#VM_ARRAY[@]}" ]]; then
    selected_vm="${VM_ARRAY[$((choice-1))]}"
    vm_ip=$(echo "$selected_vm" | awk '{print $2}')
    echo "Connecting to $selected_vm..."
    ssh codexmcp@"$vm_ip"
else
    echo "Invalid selection."
fi

How this works:

  • It reads all the YAML files in the livelaunchers directory.
  • Each YAML defines VM names and IPs.
  • It builds a quick menu: “Select a VM to SSH into.”
  • You pick the number — and it SSH’s you right in.

Why I’m using this (for now):

When the CodexMCP stack builds VMs, it does also populate DNS, so eventually these VMs can be reached by name.

But right now, since I’ve split up the configs (not one giant monolithic VM file anymore), the DNS launcher isn’t wired up to read all the split configs yet. That’ll get there, but while I’m in the middle of this work, this quick SSH script makes life easier.

This way, no matter how many times I rebuild parts of the stack — I can SSH into any piece of it in two keystrokes.

--Why?
--Bryan Vest