I like posting scripts. I am proud of most of them. I mentioned before that I run WordPress trunk and that every day, the auto upgrade script runs, upgrades this blog and sends me a detailed email regarding the upgrade. Not only does this help me keep track of changes from revision to revision without having to go browsing the repository, it gives me a handy reference in case I have to roll back.
Here is the script I run. It is a PHP command line script (I do most of my CLI scripting in PHP as I’m fluent in it).
#!/usr/bin/php
< ?php
/* Get info from the WordPress repository regarding trunk. We will use this to parse out the latest revision number */
$svninfo = shell_exec('svn info /root/working_copies/wptrunk/trunk/');
$lines = explode("n", $svninfo);
$bits = explode(' ', $lines[7]);
$oldrev = $bits[3];
/* I use shell_exec() because the output of the CLI commands will be returned. I'll be able to add this to the email */
$log = "PROCESS LOGn---------------nn";
$log .= shell_exec('svn up /root/working_copies/wptrunk/trunk/');
$log .= shell_exec('svn export --force /root/working_copies/wptrunk/trunk /home/techno/public_html/');
/* Get the revision number of the working copy. This is the new revision number */
$svninfo = shell_exec('svn info /root/working_copies/wptrunk/trunk/');
$lines = explode("n", $svninfo);
$bits = explode(' ', $lines[7]);
$newrev = $bits[3];
/* Pass the revision info along to be included in the email */
$details = "nnOld Revision: $oldrevnNew Revision: $newrevnnn";
/* Use the revision numbers to determine the log of changes between them. Add for email. */
$history = "SVN LOGn---------------nn";
$history .= shell_exec("svn log -r $oldrev:$newrev /root/working_copies/wptrunk/trunk/");
$history .= "nn";
/* Grab detailed changes (diff) between revisions. Add to email. */
$history .= "SVN DIFFn---------------nn";
$history .= shell_exec("svn diff -r $oldrev:$newrev http://svn.automattic.com/wordpress/trunk/");
$history .= "nn";
/* Put the pieces together for the email, then send */
$message = $details . $history . $log;
mail('aaron@technosailor.com','WordPress SVN Update', $message, 'From: aaron@technosailor.com');
?>
This sends me an email like the one I got the other night:
Old Revision: 4863
New Revision: 4871
SVN LOG
---------------
------------------------------------------------------------------------
r4863 | ryan | 2007-02-02 11:38:26 -0500 (Fri, 02 Feb 2007) | 1 line
Check page ID only if is_page. fixes #3049
------------------------------------------------------------------------
r4865 | ryan | 2007-02-02 19:56:23 -0500 (Fri, 02 Feb 2007) | 1 line
Typo fix from charleshooper. fixes #3743
------------------------------------------------------------------------
r4866 | ryan | 2007-02-05 16:29:39 -0500 (Mon, 05 Feb 2007) | 1 line
Disambiguate queries. Props mhyk25. fixes #3747
------------------------------------------------------------------------
r4867 | ryan | 2007-02-05 16:37:47 -0500 (Mon, 05 Feb 2007) | 1 line
Make DB_COLLATE blank by default so that MySQL will choose the default collation for the charset. #3517
------------------------------------------------------------------------
r4870 | ryan | 2007-02-05 20:44:23 -0500 (Mon, 05 Feb 2007) | 1 line
XMLRPC changes from Joseph.
------------------------------------------------------------------------
r4871 | ryan | 2007-02-06 15:12:53 -0500 (Tue, 06 Feb 2007) | 1 line
Send content type header. Props nbachiyski. fixes #3754
------------------------------------------------------------------------
SVN DIFF
---------------
Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php (revision 4863)
+++ wp-incmVFW2VW' &Wf6CsФsBbsBb Т F6G27V'7G"F6G2"Т FWE6G27V'7G"FWE6G2"Т b7G&VF6G2fwCТАF6G2"B6FVv'BF6G2#ТF6G2"BGwF"fwC7C&6B6FVv'BF6G2#Т b7G&VFWE6G2fwCТАFG2GwF"fwCvWE6%4TT5B7EBe$GwF"fwC7C&6BtU$R6FVv'BFWE6G2"ТFG2GwF"fwCvWE6%4TT5B7EBe$GwF"fwC7C&6BtU$RGwF"fwC7C&6B6FVv'BFWE6G2"Т b5'&FG2ff6VBFG2fwCТ f&V6FG22FBТ FWE7G2"FB#Т FWE7G27V'7G"FWE7G2"Т Т b7G&VFWE7G2fwCТАFWE6G2"BBBFWE7G2#ТFWE6G2"BGwF"fwC7G2BBFWE7G2#Т V6PТ FWE6G2rsТ ФFWw֖6VFW2gV7F2 УТw֖6VFW2gV7F2 &Wf6Cc2Тw֖6VFW2gV7F2 &Wf6CsФ3#r3#r РТ FF2wEF2Т b76WBFF5FFUҒТАFF5FF5UFWwfVSТFF5FFUFWwfVSТ w66U6WBvF2rFF2vF2rТ V6RТ w66U6WBFFRFWwfVRvF2rФFW'2 УТ'2 &Wf6Cc2Т'2 &Wf6CsФ##r##r Т 'wvU&VEFFR fwCG&VEFFRТ 'wvU&FW" fwCGvRfwCVU&FW"Т 'wWF%B fwCFWF"fwCBТА'wWF%F7W6W&R fwCFWF"fwCF7PТ'wWF%F7R fwCFWF"fwCF7PТ РТ &WGW&GvU7G'V7BФFWw6fr6R УТw6fr6R &Wf6Cc2Тw6fr6R &Wf6CsФRrRr ТFVfRtD%55t$Brw77v&BrB77v&@ТFVfRtD%5Brv6Ɔ7BrR66RRvwBVVBF6vRF2fVPТFVfRtD%4%4UBrwWFcrТFVfRtD%4DRrwWFcvVW&6rТFVfRtD%4DRrrrРТR6fRVFR7FF2RFF&6RbRvfRV6VVR&VfТGF&U&VfwwsǒV&W'2WGFW'2BVFW'66&W2V6RФFWwF֖FWWG& УТwF֖FWWG& &Wf6Cc2ТwF֖FWWG& &Wf6CsФ"b"Â Т&WV&U6RvF֖rТ&WV&U6R%5Du2r'72rРТVFW"t6FVBGSrvWEFvFGRrs6'6WCrvWEFv&u6'6WBrТТ7vF6EtUEvuРТ66Rv6֖vƖ2rРХ$4U52pТРХR&Bv&u6W2wG'VG'Vw֖6VFW2VW' ХR&Bv&u6W2wG'VG'Vw֖6VFW2gV7F2 ХR&Bv&u6W2wG'VG'V'2 ХR&Bv&u6W2wG'VG'Vw6fr6R ХR&Bv&u6W2wG'VG'VwF֖FWWG& РФfWF6rWFW&FVFr&Bv&u6W2wG'VG'Vw6FVBVv26WBpХWFFVBWFW&F&Wf6sbРХWFFVBF&Wf6CsФW'B6WFR6FS
Nice huh?
Update: Use this script at your own risk. The WordPress trunk is not supported by WordPress. If you use this script without understanding how to roll back, it’s all on you. If you break your blog, no one is going to help you!
Commenter Rick explains the systems requirements:
- Shell access; the command “php wordpress-update-cli.php” would otherwise be unable to run.
- Crontab; if you wanted to automate the running of the script on a regular basis.
- php 4.0.1+ or 5+; shell_exec() would otherwise be unavailable. The other prominent function call, explode(), is available from 4+. Safe mode must be set to Off to use shell_exec().
- SVN installed on the server in order to use svn command from the shell.

About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He is the Director of Technology at b5media and is available for consulting.
looks realy great. One day I will try to do it in a similar way.
Thanks, Markus. Would love to see what you comew up with when you do. :)
Hi,
What are the server requirements for using this script?
As asked before what are the requirements and also what if the hosting provider upgrades wordpress automatically. Wont it interfere with this script then.
[...] My Script for Auto WordPress Upgrade,作者提供了一个php脚本范例,用于每天自动从WordPress SVN上获得最新版本,同时发送一封E-mail到自己的邮箱,内容详述更新内容和细节。推荐有一定脚本基础的用户参考使用。 [...]
This may be a silly question, but wouldn’t it be a neat idea to build this into some sort of upgrade application that one could use without having to be on the bleeding edge? The problem with WordPress is that the installation process is from the 1980’s. If your script will work, it’s a great starting point.
Peace,
Gene
I’m not sure what the exact server requirements would be, but I can take a guess:
1) Shell access; the command “php wordpress-update-cli.php” would otherwise be unable to run.
2) Crontab; if you wanted to automate the running of the script on a regular basis.
3) php 4.0.1+ or 5+; shell_exec() would otherwise be unavailable. The other prominent function call, explode(), is available from 4+. Safe mode must be set to Off to use shell_exec().
4) SVN installed on the server in order to use svn command from the shell. (Not too sure about this one, though it seems reasonable. I’m not sure how native the svn command, whether it needs extra software or not, etc.)
Ajay: Rick nailed them.
Anshuk: If your host auto upgrades anything of yours, it’s time to find a new host.
BloggingPro China: Uh…. ;)
Gene: Sure, it’s called http://FTP. :)
Is there a way to point the script to the stable release Subversion repository? If so, I’m ’bout it ’bout it! ;o)
Why would you do that, Jonathon? If you want stable just go and download the thing from wordpress.org. Stable is only released ever so often, not something you’d want to put on cron and upgrade every night.
Laziness, I suppose! :o) How “stable” is the nightly? I mean, you’re running it, so it must be somewhat okay.
It’s stable today! Can’t guarantee tomorrow! :) It’s definitely not supported! It’s definitely for advanced users who understand the ins and outs of WordPress and SVN.
Thanks Aaron and Rick.
BTW, I listed the post on WLTC.
Thanks, Ajay. Updated the post to make sure people aren’t using this flippantly and hoping for support. ;)
[...] Fantástico script que te tendrá actualizado automáticamente a la nueva versión de Wordpress 2.1. [...]
[...] como o One Click Install da Dreamhost so sua melhor opo? Ento esta na hora de voc conhecer um script que automatiza o processo de upgrade. Para ser um blogueiro preguioso, mas atualizado, requer [...]
[...] My Script for Auto WordPress Upgrade » Technology, Blogging and New Media “[This] auto upgrade script runs, upgrades this blog and sends me a detailed email regarding the upgrade.” (tags: WordPress script Plugin backup upgrade) [...]
You’re welcome :)
[...] script that I can find out there and recently I stumbled upon a post by Aaron Brazell about an Automated WordPress Upgrade Script he [...]
[...] have Subversion installed and you’re running WordPress on a *nix server, both Red Monk and Aaron Brazell have bash files to help you automatically update all of your WordPress [...]
[...] Aaron Brazell of Technosailor wrote a PHP script that will take care of the upgrade for you. Use this with extreme care. You can either execute as any other PHP file, running PHP from your shell or using a PHP-shell, executed as a cron job etc. [...]
[...] May 22 - 4:30PM EDT Upgrade script and subversion repositories prepped for switch to WordPress 2.2. We chose revision 5505 as most of [...]
i wrote a wp upgrade script in bash (so it’s a shell script, really). it makes a backup of the wp-db and -fs, turns of plugins and syncs with the latest tagged version using “svn sw”.
you can fetch a tar.gz-version of it on http://futtta.be/download/WPuppy.tar.gz.
more info (in dutch, but there’s an auto translate link in the upper right corner) on: http://blog.futtta.be/2007/09/26/wordpress-automagisch-upgraden-nu-ook-met-hondje/
[...] My Script for Auto WordPress Upgrades [...]