Bash Script for Updating Multiple WordPress Blogs

While WordPress has finally added core update in its latest 2.7 branch, there are still people out there that will need to update multiple blogs quickly, and if you are managing your blog installations with Subversion, you can go through and update them all very quickly.

Of course, to update multiple blogs, you’ll have to go through to each folder, run the proper Subversion command, and then move onto the next folder. This can be a time consuming process if you have more than five or six blogs to do for each release.

I have previously written a post on Geeks are Sexy about updating WordPress blogs with Subversion. Read that first if you aren’t using Subversion.

Bash Script

The easiest way to help automate simple tasks on a Linux web server is to Bash script it. This is a very simple scripting language that allows you to do commands and using simple looping and an array, you can quickly do those commands multiple times for multiple blogs.

When I was working for Bloggy Network, I used a similar script to upgrade upwards of forty WordPress powered blogs in less than five minutes.

The following script assumes that your blogs are all in sub-folders under where this script will be placed. If the blogs are in different locations, make sure to include that in your path determinations either when you assign array values or as another variable you can make use of.



for a in 1 2 3
echo “Giving ${blog[$a]} an Upgrade”
cd ${blog[$a]}
svn sw http://svn.automattic.com/wordpress/tags/2.7.1 .
cd ..

exit 0

This code basically creates an array, and then cycles through the array, going into each folder, and switching the blog to the latest version of WordPress. The only editing you’ll need to do to before using this script is change the blog variable, and change the tagged version number in the svn sw command. If you are using trunk, you don’t have to do this and instead of /tags/version.number you’d just put /trunk.

While I don’t recommend running on trunk, especially for your production blogs, I know many people that do.

If you add more items to the array, you have to make sure that you add more numbers to your for loop. So if there were ten items in the blog array, you would want to make sure to change the for a line to: for a in 1 2 3 4 5 6 7 8 9 10.

Bash scripting is a relatively simplistic language, but can be very powerful.

This script could be easily modified to include error checking, create a log file where you can look over which files were changed, and when they were last changed, and you could also make it so that when the script ran, it asked you for which version number to use in the switch command.

I have also used Bash scripting to upload the same plugins to a number of different blogs all at once, make edits to the .htaccess file, and delete certain files.

If you have access to your server and can run Bash scripts, I suggest you play around with them, as they can be a great tool when the right circumstances rear their ugly head.

  1. By Dustin Boston posted on February 19, 2009 at 5:34 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    That’s a great tip. Man how I miss running my own server. This stuff is so tedious on shared hosting.

  2. By china wholesale posted on July 12, 2009 at 12:33 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Thanks for the article, it was a good read indeed

  3. By Glenn Jimerson posted on August 3, 2009 at 11:47 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Thank you David! The script worked beautifully. I was able to switch my old WP installs to the new SVN updatable type. One thing I’d recommend changing is the URL in line 11 to: svn sw http://core.svn.wordpress.org/tags/2.8.3 . svn.automattic.com/wordpress gave me an error.

  4. By wholesalers china posted on November 7, 2009 at 6:30 am
    Want an avatar? Get a gravatar! • You can link to this comment

    Love this post! Cool WP template list here. I will used them in my personal blog. Thank you for sharing these.

  5. By Jericon posted on December 9, 2009 at 11:44 am
    Want an avatar? Get a gravatar! • You can link to this comment

    You could simplify this script by changing it.

    blog=( domain1.com domain2.com domain3.com )

    for a in blog[@]; do

  6. TrackbackUpdate multiple WordPress blogs with a Subversion bash script | WordPress Philippines