Last active
May 8, 2020 13:48
-
-
Save jamesstout/c19c227d1ac7dd37108ecbbf5c52eea7 to your computer and use it in GitHub Desktop.
docker-image-refresh.sh
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
#!/usr/bin/env bash | |
logExt="$(date +%Y-%m-%d).log" | |
LOG_FILE="/var/services/homes/james/logs/$(basename "$0").$logExt" | |
WORK_DIR=$(mktemp -d) | |
# check if tmp dir was created | |
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then | |
echo "Could not create temp dir" | |
exit 1 | |
fi | |
# deletes the temp directory | |
function cleanup { | |
rm -rf "$WORK_DIR" | |
} | |
# register the cleanup function to be called on the EXIT signal | |
trap cleanup EXIT | |
# get list of all image:rev | |
# not mariadb|redis as they cause issues | |
# not |headphones|nzbget as not used | |
for image in $(docker ps --all | grep -Ev 'mariadb|redis|headphones|nzbget|ID' | awk '{ print $2 }' | grep -v '\d+'); do | |
echo "$image" | |
docker pull "$image" | tee -a "$LOG_FILE" | |
done | |
# if the docker pull retreived newer images | |
# get the names, and email me | |
if [ "$(grep -c newer "$LOG_FILE")" -gt 0 ]; | |
then | |
# the awk is to remove leading spaces .. causes issues with mail as does the Status:, hence the cut | |
grep newer "$LOG_FILE" | cut -d ":" -f2- | awk '{$1=$1};1' > "$WORK_DIR"/report.txt | |
cat > "$WORK_DIR"/mail.txt <<EOF | |
To: [email protected] | |
From: [email protected] | |
Subject: docker image refresh | |
EOF | |
cat "$WORK_DIR"/mail.txt "$WORK_DIR"/report.txt | /usr/bin/ssmtp [email protected] | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment