gets ips and ports of containers and checks if they return a valid HTTP response

PHOTO EMBED

Sat Mar 26 2022 12:18:07 GMT+0000 (Coordinated Universal Time)

Saved by @ejfhnwouhqw #shellscript

#!/bin/bash
MYIP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
for i in $(docker ps --format '{{.Names}}'); do
    docker port $i | grep -oP '(?<=0:)[1-9].*' | while read -r MYPORT; do
        if [[ -n $MYPORT ]]; then
            MYRESPONSE=$(curl -Is --max-time 0.5 $MYIP:$MYPORT | head -1 | grep -oP '[0-9][0-9][0-9]')
            pat="2|3"
            if [[ ${MYRESPONSE:0:1} =~ $pat ]]; then
                printf "| %20s | %-20s | %-10s | \n" "$i" "$MYIP:$MYPORT" "$MYRESPONSE"
            fi
        fi
    done
done
content_copyCOPY