Automating WordPress updates with cron and the wp-cli

Ain’t nobody got time to worry about updates. I’d rather have it break while updating than have it hacked by a script kiddie because I’ve neglected to login for a while. We will see if this ever breaks anything.

Install WordPress-CLI if you have not already.

Add all your sites to the update_wp.sh script:

#!/bin/bash
declare -a arr=(
  "anthonypenner.com" 
  "trekcamp.org"
  "etc"
)

for i in "${arr[@]}"
do
  echo $i
  cd /usr/share/nginx/html/$i
  sudo -u nobody wp core update
done

NOTE: Substitute /usr/share/nginx/html for the directory that holds your WordPress sites. Change user nobody to the user that owns the aforementioned directories. Check with ls -al, it might be the user that apache/nginx runs as, check that with top, htop, or ps -aux

Make sure it’s executable:

chmod +x update_wp.sh

Run the script daily and live dangerously!

30 2 * * * bash /home/anthony/update_wp.sh >/dev/null 2>&1

Published by

Anthony

Anthony loves open source software. Especially Linux and Ruby on Rails. He enjoys tinkering with his Raspberry Pi projects, writing code late at night, and drinking coffee. He aspires to be a Linux guru and software development magician. He is currently reading books on AI.

Leave a Reply

Your email address will not be published. Required fields are marked *