This page is an archive of my old blog. Please visit DavidTucker.net for my current blog.
This site is no longer being maintained and commenting is disabled.

Updating Multiple WordPress Installations Programatically

Shell scripts are great (of course - this is only going to work if you are on a Linux server). This script should also preserve plug-ins and themes (assuming that you keep data in the standard directories).

NOTICE: I cannot guarantee the functionality of this script. It is meant to be used as a guide. Backup your WordPress installations before using this script.

CODE:
  1. #!/bin/bash
  2.  
  3. ###
  4. # CONFIGURATION
  5. ###
  6.  
  7. # List Directory Where the Update Script is Held
  8. SCRIPT_DIRECTORY=/home/david
  9.  
  10. # List Each Directory on Your Server that Contains a WordPress Installation
  11. installations[0]=/var/www/html/blog1
  12. installations[1]=/var/www/html/blog2
  13.  
  14. ###
  15. # DO NOT EDIT BELOW THIS LINE
  16. ###
  17.  
  18. rm -Rf "$SCRIPT_DIRECTORY/wordpress"
  19. cd "$SCRIPT_DIRECTORY"
  20. wget http://wordpress.org/latest.zip --output-document wordpress.zip
  21. unzip wordpress.zip
  22.  
  23. for installation in ${installations[@]}
  24. do
  25.         echo "Updating $installation..."
  26.         cp "$SCRIPT_DIRECTORY/wordpress/*" "$installation"
  27.         cp -Rf "$SCRIPT_DIRECTORY/wordpress/wp-admin" "$installation/"
  28.         cp -Rf "$SCRIPT_DIRECTORY/wordpress/wp-includes" "$installation/"
  29.         cp -Rf "$SCRIPT_DIRECTORY/wordpress/wp-content/themes/*" "$installation/wp-content/themes"
  30.         cp -Rf "$SCRIPT_DIRECTORY/wordpress/wp-content/plugins/*" "$installation/wp-content/plugins"
  31. done
  32.  
  33. echo "Updates Complete..."

You will have to update two settings in the script. First, you will need to update the SCRIPT_DIRECTORY variable. This will be the directory where wordpress will be downloaded and unzipped. Next, you will need to update the array of wordpress installations. Be sure to increment the number in the array.

You can download the script below. This script will not update your database tables - you will have to log into the administrator and click through the update process there.

Download Code
Update Script




3 Responses to “Updating Multiple WordPress Installations Programatically”

  1. ryan says:

    wicked, have you made the switch to linux? if so post your which disto/experience so far i’d be keen to know…

    thanks…

  2. I found it to very informational, it will certainly provide help in programming.

    This list will be very useful in the future.

    Got to bookmark this one!

  3. Hey David,

    I just found your site and fully intend on chopping up your code to make it work for me. Looks really elegant. Thank you for being so cool about sharing. I’ll make sure you get a nice link in my post!

    Josh