forked from d-Rickyy-b/motd-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
60-docker
32 lines (27 loc) · 831 Bytes
/
60-docker
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
#!/bin/bash
# This script lists all docker containers and their status
# Taken from https://github.com/yboetz/motd/blob/master/60-docker
# set column width
COLUMNS=2
# colors
green="\e[1;32m"
red="\e[1;31m"
undim="\e[0m"
mapfile -t containers < <(docker ps -a --format '{{.Names}}\t{{.Status}}' | awk '{ print $1,$2 }')
out=""
for i in "${!containers[@]}"; do
IFS=" " read -r name status <<< "${containers[i]}"
# color green if service is active, else red
if [[ "${status}" == "Up" ]]; then
out+="${name}:,${green}${status,,}${undim},"
else
out+="${name}:,${red}${status,,}${undim},"
fi
# insert \n every $COLUMNS column
if [ $(((i+1) % COLUMNS)) -eq 0 ]; then
out+="\n"
fi
done
out+="\n\n"
printf "\ndocker status:\n"
printf "$out" | column -ts $',' | sed -e 's/^/ /'