Last active
July 27, 2023 07:42
-
-
Save gcommit/7594f793b871c819084c7e629031cf9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
app=$1 | |
if [ "$#" -ne 1 ]; then | |
echo "./docker_network.sh [app_id]" | |
else | |
case "$1" in | |
help) | |
echo "./docker_network.sh [app_id]" | |
;; | |
*) | |
if [ -f /tmp/inspect.txt ]; then | |
rm /tmp/inspect.txt | |
echo "inspect.txt found! Will remove now" | |
fi | |
if [ -f /tmp/inspect2.txt ]; then | |
rm /tmp/inspect2.txt | |
echo "inspect2.txt found! Will remove now" | |
fi | |
docker network inspect $app | grep Name > /tmp/inspect.txt | |
sed -i '1d' /tmp/inspect.txt | |
cut -d' ' -f18- /tmp/inspect.txt > /tmp/inspect2.txt | |
sed -i 's/^.//' /tmp/inspect2.txt | |
sed -i 's/.\{2\}$//' /tmp/inspect2.txt | |
clients_array=( $(cat /tmp/inspect2.txt) ) | |
for i in "${clients_array[@]}"; do | |
docker network disconnect -f $app $i | |
echo "Disconnected $i from $app" | |
done | |
echo "Finished [SUCCESS] !" | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment