Add script to get docker logs

This commit is contained in:
Christopher
2023-10-10 19:00:15 -05:00
parent 14d8e7eea8
commit 900c46476e
2 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
## Why?
This is a handy script to get the Docker container logs.
## How to use?
```bash
bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/get-docker-logs/run.sh)"
```

33
get-docker-logs/run.sh Normal file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
# Function to combine container info for display
combine_container_info() {
local id="$1"
local name="$2"
local image="$3"
if [ -z "$name" ]; then
echo "$id ($image)"
else
echo "$name"
fi
}
# Fetch all running container info
CONTAINERS=()
while IFS= read -r line; do
CONTAINERS+=("$line")
done < <(docker ps --format "{{.ID}}|{{.Names}}|{{.Image}}" | while IFS="|" read -r id name image; do
combine_container_info "$id" "$name" "$image"
done)
# Prompt the user to select a container
echo "Select a container to fetch logs:"
select CONTAINER_CHOICE in "${CONTAINERS[@]}"; do
# Extract the container ID/name from the selected option
CONTAINER_ID_OR_NAME=$(echo $CONTAINER_CHOICE | awk '{print $1}')
# Fetch and display the logs for the selected container
docker logs $CONTAINER_ID_OR_NAME
break
done