Dave Kopecek bio photo

Dave Kopecek

The Blog That Time Forgot.

Email Twitter Facebook LinkedIn Instagram BitBucket Github Stackoverflow Pinterest

Wordpress installs multiply like bunnies. If you’ve got several WordPress domains hosted on a single server it’s easy to loose track of installed versions. This one-line wonder will sniff out WordPress powered sites and grab their version number. Drop it in a CRON that runs once a month and you’ll get regular reminders of what’s lurking out on your server.

WordPress installs contain the file version.php with the variable $wp_version. Find all the version.php files, grab the variable and you’re golden. Here’s the basic locate command:

locate /wp-includes/version.php | xargs grep '$wp_version ='

That’s nice enough, but we can get a bit better. The server I’m targeting stores all virtual hosts in the directory /var/www/vhosts. We can use the cut command to snip that from the display, sort the output by domain name and email the results.

locate /wp-includes/version.php | xargs grep '$wp_version =' | cut -d'/' -f5,6,7,8,10  | sort | mail -s "WordPress Installs on Server XYZ" your-email@yourdomain.com

You’ll get an email with results like this:

foobar.com/version.php:$wp_version = '3.0.1';
whatsit.com/version.php:$wp_version = '2.7.1';
whizzbang.com/version.php:$wp_version = '2.9.1';
widget.net/wp-includes/version.php:$wp_version = '2.9.1';

For extra credit you could sort by version number, but there’s no need to be an overachiever here. Quit while you’re ahead. The script uses locate, so make sure you run updatedb periodically.