Skip to content

Instantly share code, notes, and snippets.

@DrizzlyOwl
Last active April 19, 2017 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrizzlyOwl/b4ad4a449008e81fa793594be5955cc3 to your computer and use it in GitHub Desktop.
Save DrizzlyOwl/b4ad4a449008e81fa793594be5955cc3 to your computer and use it in GitHub Desktop.
#! /bin/bash
#
# Author: Ash Davies <github.com/drizzlyowl>
# Requires: wp-cli, curl, python, sendmail
# Description: Checks through all vhost directories to determine whether WordPress is
# installed and whether the version is out of date and sends a summary email to
# a recipient
#
touch $HOME/wordpress-versions.tmp
echo "From: Your-Hosting-Name <hosting@your-domain.tld>" > $HOME/wordpress-versions.tmp;
echo "To: recpient@your-domain.tld" >> $HOME/wordpress-versions.tmp
echo "Subject: WordPress Versions for sites hosted on $HOSTNAME" >> $HOME/wordpress-versions.tmp;
LATEST_VER=$(curl -s 'https://api.github.com/repos/wordpress/wordpress/tags' | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[0]["name"]');
for d in /var/www/vhosts/*/httpdocs/current/ ;
do (
cd "$d";
if $(wp core is-installed --quiet); then
echo "";
echo "--------------";
wp option get home;
CURRENT_VER=$(wp core version);
if [ "$CURRENT_VER" == "$LATEST_VER" ]; then
echo "Up to date!";
else
echo "Current version: $CURRENT_VER";
echo "Latest version: $LATEST_VER";
fi
fi
);
done >> $HOME/wordpress-versions.tmp
if [ -s $HOME/wordpress-versions.tmp ]
then
sendmail -F "hosting@your-domain.tld" -f "from@your-domain.tld" recipient@your-domain.tld < $HOME/wordpress-versions.tmp
fi
# Optional: delete resulting file after processing
# rm $HOME/wordpress-versions.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment