-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockers.sh
More file actions
37 lines (29 loc) · 1.07 KB
/
Copy pathdockers.sh
File metadata and controls
37 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Define Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
BOLD='\033[1m'
echo -e "${BOLD}--- Disk Usage ---${NC}"
df -h / | grep -v Filesystem
echo ""
echo -e "${BOLD}--- Docker Containers ---${NC}"
# Header: Added more room for Status (30) and moved Ports to last
printf "${BOLD}%-20s %-30s %-15s %-20s${NC}\n" "NAME" "STATUS" "SIZE" "PORTS"
# Get data from docker and loop through it
docker ps -a --size --format "{{.Names}}|{{.Status}}|{{.Ports}}|{{.Size}}" | while read -r line; do
NAME=$(echo $line | cut -d'|' -f1)
STATUS=$(echo $line | cut -d'|' -f2)
# Clean Ports
PORTS=$(echo $line | cut -d'|' -f3 | sed 's/0.0.0.0://g; s/::://g; s/\/tcp//g; s/\/udp//g; s/,//g')
# Clean Size
SIZE=$(echo $line | cut -d'|' -f4 | sed 's/ (virtual.*//')
# Apply Color based on Status
if [[ $STATUS == Up* ]]; then
COLOR=$GREEN
else
COLOR=$RED
fi
# Print formatted row: Name (20), Status (30), Size (15), Ports (20)
printf "%-20s ${COLOR}%-30s${NC} %-15s %-20s\n" "$NAME" "$STATUS" "$SIZE" "$PORTS"
done