mirror of
https://github.com/bigbeartechworld/big-bear-scripts.git
synced 2026-06-02 05:01:41 -04:00
Add script to get docker logs
This commit is contained in:
9
get-docker-logs/README.md
Normal file
9
get-docker-logs/README.md
Normal 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
33
get-docker-logs/run.sh
Normal 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
|
||||
Reference in New Issue
Block a user