Combining/interleaving output from multiple hosts #1251
andyjeffries
started this conversation in
Ideas
Replies: 1 comment
-
|
If anyone else comes across this issue, here's a bash script to do it: #!/bin/bash
# Define the list of servers
servers=(
"user@web1.example.com"
"user@web2.example.com"
# Add more servers as needed
)
# Function to clean up background processes
cleanup() {
echo "Cleaning up..."
for pid in "${pids[@]}"; do
kill "$pid" 2>/dev/null
done
}
# Trap the EXIT signal to run the cleanup function
trap cleanup EXIT
# Array to hold the process IDs of background jobs
pids=()
for server in "${servers[@]}"; do
# Replace yourorg/project with your Docker image name
ssh "$server" "docker ps | grep 'yourorg/project' | awk '{print \$1}' | xargs -r docker logs -f 2>&1 | sed 's/^/[$server] /'" &
pids+=($!)
done
# Wait for all background jobs to finish
wait |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Would be great if there was a way of doing something like this:
And having it tail the web containers across all hosts, preceeding each line with the hostname/container name (in a different colour) of each one.
I understand there are companies like Basecamp where the scale would make this unweildy, but for smaller uses (think a couple of servers each, for a couple of different roles) this is super useful. I used Kubetail in the Kubernetes world before we moved over to deploying via Kamal.
Maybe there's something already out there that we can use (or wrap)?
Beta Was this translation helpful? Give feedback.
All reactions