40 lines
2.2 KiB
Bash
40 lines
2.2 KiB
Bash
# Title: Container - Container details
|
|
# ID: CT_Container_details
|
|
# Author: Carlos Polop
|
|
# Last Update: 22-08-2023
|
|
# Description: Get container details
|
|
# License: GNU GPL
|
|
# Version: 1.0
|
|
# Functions Used: containerCheck, echo_no, print_2title, print_list
|
|
# Global Variables: $containerType
|
|
# Initial Functions: containerCheck
|
|
# Generated Global Variables: $dockercontainers, $podmancontainers, $lxccontainers, $rktcontainers, $containerCounts
|
|
# Fat linpeas: 0
|
|
# Small linpeas: 1
|
|
|
|
|
|
print_2title "Container details"
|
|
print_list "Is this a container? ...........$NC $containerType"
|
|
|
|
print_list "Any running containers? ........ "$NC
|
|
# Get counts of running containers for each platform
|
|
dockercontainers=$(docker ps --format "{{.Names}}" 2>/dev/null | wc -l)
|
|
podmancontainers=$(podman ps --format "{{.Names}}" 2>/dev/null | wc -l)
|
|
lxccontainers=$(lxc list -c n --format csv 2>/dev/null | wc -l)
|
|
rktcontainers=$(rkt list 2>/dev/null | tail -n +2 | wc -l)
|
|
if [ "$dockercontainers" -eq "0" ] && [ "$lxccontainers" -eq "0" ] && [ "$rktcontainers" -eq "0" ] && [ "$podmancontainers" -eq "0" ]; then
|
|
echo_no
|
|
else
|
|
containerCounts=""
|
|
if [ "$dockercontainers" -ne "0" ]; then containerCounts="${containerCounts}docker($dockercontainers) "; fi
|
|
if [ "$podmancontainers" -ne "0" ]; then containerCounts="${containerCounts}podman($podmancontainers) "; fi
|
|
if [ "$lxccontainers" -ne "0" ]; then containerCounts="${containerCounts}lxc($lxccontainers) "; fi
|
|
if [ "$rktcontainers" -ne "0" ]; then containerCounts="${containerCounts}rkt($rktcontainers) "; fi
|
|
echo "Yes $containerCounts" | sed -${E} "s,.*,${SED_RED},"
|
|
|
|
# List any running containers
|
|
if [ "$dockercontainers" -ne "0" ]; then echo "Running Docker Containers" | sed -${E} "s,.*,${SED_RED},"; docker ps | tail -n +2 2>/dev/null; echo ""; fi
|
|
if [ "$podmancontainers" -ne "0" ]; then echo "Running Podman Containers" | sed -${E} "s,.*,${SED_RED},"; podman ps | tail -n +2 2>/dev/null; echo ""; fi
|
|
if [ "$lxccontainers" -ne "0" ]; then echo "Running LXC Containers" | sed -${E} "s,.*,${SED_RED},"; lxc list 2>/dev/null; echo ""; fi
|
|
if [ "$rktcontainers" -ne "0" ]; then echo "Running RKT Containers" | sed -${E} "s,.*,${SED_RED},"; rkt list 2>/dev/null; echo ""; fi
|
|
fi |