Last active
April 19, 2017 08:17
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 | |
# | |
# 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