Skip to content

Instantly share code, notes, and snippets.

@matsubo
Last active October 17, 2023 04:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matsubo/159ba160581ff53fce09 to your computer and use it in GitHub Desktop.
Save matsubo/159ba160581ff53fce09 to your computer and use it in GitHub Desktop.
Shell script to keep updated wordpress core and plugins.

Setup

Install wp command

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Setup cron

% wget  https://gist.githubusercontent.com/matsubo/159ba160581ff53fce09/raw/38cb19873444c30984661beaf5ac67c05731227f/wordpress_update.sh
% chmod 755 wordpress_update.sh
% crontab -e
15 21 * * * /path/to/wordpress_update.sh
#!/bin/zsh
# -------------------------------------
# Usage: % ./wordpress_update.sh
# -------------------------------------
# to be strict syntax checker
set -e
# set low priority
renice -n 19 $$
WPS=(
"/path/to/wordpress1/"
"/path/to/wordpress2/"
)
PATH=/usr/local/bin:$PATH
for i in $WPS
do
echo "Processing: $i"
cd $i
echo " Upgrading plugins."
wp plugin update --all
echo " Upgrading themes."
wp theme update --all
echo " Upgrading Wordpress."
wp core update && wp core update-db
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment