Jafner.net/homelab/server/scripts/nas_down.sh

17 lines
671 B
Bash
Raw Normal View History

2022-08-18 10:32:14 -07:00
#!/bin/bash
2022-08-18 11:00:41 -07:00
NAS_DEPENDENTS=""
2022-08-18 10:32:14 -07:00
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
2022-08-18 10:58:35 -07:00
#echo "======== CHECKING $CONTAINER_NAME ========"
2022-08-18 10:57:49 -07:00
echo "$CONTAINER_MOUNTS" | grep -q /mnt/nas
2022-08-18 10:52:31 -07:00
MATCH=$?
2022-08-18 10:57:09 -07:00
if [ $MATCH == 0 ]; then
2022-08-18 11:00:41 -07:00
echo "$CONTAINER_NAME"
2022-08-18 11:04:14 -07:00
NAS_DEPENDENTS+="$CONTAINER_NAME\n"
2022-08-18 10:53:37 -07:00
fi
2022-08-18 11:00:41 -07:00
done
echo "NAS_DEPENDENTS="
2022-08-18 11:04:14 -07:00
echo -e "${NAS_DEPENDENTS}"