Files
cosmoserver/files/scripts/check_cosmostat.sh

29 lines
1.0 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# this was some weird testing stuff
# ------------------------------------------------------------------
# Grab the list of IPs
# ------------------------------------------------------------------
readarray -t ips < <(curl -s http://192.168.37.1:5000/client_inventory | grep ansible_host | cut -d: -f2 | awk '{print $1}')
# ------------------------------------------------------------------
# Inspect the result (optional, handy for debugging)
# ------------------------------------------------------------------
echo "Found ${#ips[@]} IP(s):"
for ip in "${ips[@]}"; do
echo " $ip"
done
# ------------------------------------------------------------------
# Use the array for example, SSH into each host
# ------------------------------------------------------------------
USER="root"
KEY="~/.ssh/id_rsa"
PORT=22
for host in "${ips[@]}"; do
echo "=== SSHing to $host ==="
ssh -o BatchMode=yes -p "$PORT" -i "$KEY" "$USER@$host" "hostname && docker ps --format=json | jq -r '.Names' | grep cosmostat"
echo
done