Finding and auto updating wordpress / themes / plugins with wp-cli

For many years I have maintained a shell script that checks and can update wordpress. Its great, it needs nearly nothing and is handy for basic diagnosis, however its not good as something that can update things on a cron so well which multiple people have asked about.

I have always suggested that if you run your own server, then a better option is wp-cli - its easy to install and could be run on a cron. This seems to be a little hard for some, unsure what to do and how to do it. So i wrote another script that finds all your wordpress installs, installs and makes sure wp-cli is going, and updates them on a cron.

This will work well at updating things, however it will also find your backups or other sites you may not want updated, and mess with them.
To avoid this place an empty file in these directories root named .noupdate

If i had a wordpress install in /home/liz/public_html/ and i have a backup in /home/liz/oldpublic_html i would run

touch /home/liz/oldpublic_html/.noupdate

So to Install and get this going here is the steps required ...

wget -O /usr/local/bin/wp-cli-cron-update.sh http://b.ri.mu/files/wp-cli-cron-update.sh
chmod +x /usr/local/bin/wp-cli-cron-update.sh

Once installed. run it once to test

/usr/local/bin/wp-cli-cron-update.sh

Once you have confirmed its working fine, then add a crontab that looks like this

0 0 * * * /usr/local/bin/wp-cli-cron-update.sh >/var/log/wp-update.log 2>&1

This will log to /var/log/wp-update.log , you may want to setup a logrotate for this log.

/var/log/wp-update {
    missingok
    daily
    create 0664 root utmp
    rotate 5
    compress
}

Feel free to change the last part to mail you like this

0 0 * * * /usr/local/bin/wp-cli-cron-update.sh | mail -s "wp-cli update" youremail@home.com

By default this will search in /var/www and /home for wordpress installs, if you need it to check another location you can use the -p option

/usr/local/bin/wp-cli-cron-update.sh -p /srv/somepath 

Please email any bugs or issues to liz at rimuhosting.com

This entry was posted in Featured, Rimuhosting. Bookmark the permalink.

One Response to Finding and auto updating wordpress / themes / plugins with wp-cli

  1. Pingback: WordPress Upgrade shell Script – plugins, themes, crontab and more! | RimuHosting Blog

Leave a Reply