-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshocker-list
executable file
·44 lines (35 loc) · 1.02 KB
/
shocker-list
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
38
39
40
41
42
43
44
#!/bin/sh
. "$(dirname "$(readlink -f "$0")")"/utils.sh
usage () {
cat << USAGE
shocker-list - list containers
Usage: shocker list
Examples:
$ shocker list # list containers
USAGE
}
[ "$#" -eq 0 ] || { usage; exit 1; }
count="$(find "${container_path}" -mindepth 1 -maxdepth 1 -type d | wc -l)"
if [ "$count" -eq 0 ]; then
printf "No containers found in ${container_path}\n" >&2
exit 0
fi
printf "%-12s %8s %-18s %s\n" 'CONTAINER_ID' 'STATE' 'IP' 'PARENT'
for container in "${container_path}"/*; do
[ -e "$container" ] || break
ps=$(basename "$container")
state=$(get_state "$ps")
ip=
case $state in
running)
ansi="1;32"
ip=$(ip netns exec "netns_$ps" ip addr 2>/dev/null \
| sed -n "s/.*inet \([^ ]\+\) .* veth1_$ps/\1/p" \
| tr -d "\n")
;;
crashed) ansi="1;31";;
* ) ansi="0";;
esac
parent="$(cat "${container}/.parent.id" 2>/dev/null)"
printf "%-12s \x1b[%sm%8s\x1b[0m %-18s %s\n" "$ps" "$ansi" "$state" "${ip:--}" "${parent:--}"
done