Jafner.net/homelab/server/scripts/nas_down.sh
2022-08-18 11:04:14 -07:00

17 lines
671 B
Bash
Executable File

#!/bin/bash
NAS_DEPENDENTS=""
for CONTAINER_ID in $(docker ps -aq) # get list of all loaded containers (running and stopped)
do
CONTAINER_NAME=$(docker ps -aq --filter "id=$CONTAINER_ID" --format '{{.Names}}') # get the container's name
CONTAINER_MOUNTS=$(docker inspect --format '{{range .Mounts}}{{println .Source}}{{end}}' $CONTAINER_ID) # print the container's volume mounts
#echo "======== CHECKING $CONTAINER_NAME ========"
echo "$CONTAINER_MOUNTS" | grep -q /mnt/nas
MATCH=$?
if [ $MATCH == 0 ]; then
echo "$CONTAINER_NAME"
NAS_DEPENDENTS+="$CONTAINER_NAME\n"
fi
done
echo "NAS_DEPENDENTS="
echo -e "${NAS_DEPENDENTS}"