Automated WordPress updates for Sympl

Back in 2020, I migrated my personal and business servers to Sympl. Several sites ran WordPress, and I wanted to automate the application of updates to WordPress itself, as well as all the plugins and themes.

I’ve previously posted about Automating WordPress updates with wp-cli, but that particular solution required me to hard-code a list of WordPress sites to update, and I wondered if there was a way to automatically find all the WordPress sites. As all WordPress sites contain a wp-config.php file, and that is unlikely to exist on other sites, I realised I could search for any directories including that file and extract the domain:

WP_SITES=($(/usr/bin/find /srv -name wp-config.php | awk -F/ '{print $3}'))

The command finds all the files under /srv with a name of wp-config.php, then uses awk to extract the third field, using / as the separator. As Sympl uses /srv/example.org as the directory structure, the third field is the site. The brackets around the subshell command convert the results (one per line) into an array, which can then be iterated over to update each site in turn.

The full scripts can be found in my Sympl scripts repository. The scripts are offered independently and are not endorsed by the Sympl project or Mythic Beasts.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.