Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cat /etc/cron.daily/wordpress
#!/bin/sh
set -e
WWW_USER="www-data"
WWW_PATH="/var/www"
WPCLI_UPDATE=`wp cli check-update --allow-root 2>/dev/null \
| grep -v "Success: WP-CLI is at the latest version." | wc -l`
if test $WPCLI_UPDATE -gt 0
then
wp cli update --allow-root --yes
fi
for wp_instance in `find ${WWW_PATH} -maxdepth 2 -name wp-config.php | xargs -L 1 dirname`
do
CORE_UPDATE=`sudo -u ${WWW_USER} \
wp core check-update --path=$wp_instance --field=version 2>/dev/null \
| grep -v "WordPress is at the latest version." | wc -l`
PLUGIN_UPDATES=`sudo -u ${WWW_USER} \
wp plugin status --path=$wp_instance 2>/dev/null | grep "^ U" | wc -l`
THEME_UPDATES=`sudo -u ${WWW_USER} \
wp theme status --path=$wp_instance 2>/dev/null | grep "^ U" | wc -l`
if test $CORE_UPDATE -gt 0 -o $PLUGIN_UPDATES -gt 0 -o $THEME_UPDATES -gt 0
then
echo "Updating ${}wp_instance}:"
echo
fi
if test $CORE_UPDATE -gt 0
then
sudo -u ${WWW_USER} \
wp core update --path=$wp_instance
sudo -u ${WWW_USER} \
wp core update-db --path=$wp_instance
fi
if test $PLUGIN_UPDATES -gt 0
then
sudo -u ${WWW_USER} \
wp plugin update --all --path=$wp_instance
fi
if test $THEME_UPDATES -gt 0
then
sudo -u ${WWW_USER} \
wp theme update --all --path=$wp_instance
fi
if test $CORE_UPDATE -gt 0 -o $PLUGIN_UPDATES -gt 0 -o $THEME_UPDATES -gt 0
then
echo
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.