Are your WordPress sites running the latest core?

In addition to hosting Drupal sites, we also host a number of WordPress sites. Similar to (checking all of our Drupal core versions)[], we needed an easy way to quickly see what versions we are running on all of our WordPress sites. Kudos to Ethan for getting this one kicked off; here is a bash script to check your definable $WEBHOME (where you deposit all of your WordPress webroots) and scan for WordPress versions.

Note: this requires bash, grep, wc, sed, awk, and tree. If your system doesn’t have tree, it’s usually pretty easy to get from EPEL/Homebrew/apt-get/[mac]ports/etc.

# Where to start scanning
# Workaround to fix awk counting below
WEBHOMECOUNT=$(($(echo "${WEBHOME}"|grep -o "/"|wc -l| sed s/\ //g)+2))
# Other projects could use 'version.php' so we include 
# 'wp-includes/' in our search to limit it to WordPress
for i in $(tree -L 5 -if ${WEBHOME} | grep 'wp-includes/version.php'); do
  SITE=$(echo $i|awk -v count="$WEBHOMECOUNT" -F/ '{for(j=count;j<=NF-2;j++) \
        printf $j"/"}' | sed 's/.$//g')
  VERSION=$(grep "wp_version = " $i|awk -F\' '{print $2}')
  echo $SITE - $VERSION

As a result, you’ll see output like this:

$ ./ - 3.0.4 - 3.0.3 - 2.8.2 - 2.0.2

If you think there’s a better way, or have any questions, let me know in the comments.

This post originally featured on the EchoDitto Labs blog.