Automation
Why waste time carrying out repetitive tasks that a computer can do for you? You’d be better off spending your time programming (or doing some more of whatever it is that you do). A computer will make a better job of it than you too.
To quote the The Pragmatic Programmer (which, incidentally, is highly recommended reading):
People just aren’t as repeatable as computers are. Nor should we expect them to be. A shell script or batch file will execute the same instructions, in the same order, time after time.
REXML could not parse this XML/HTML: <cite>– The Pragmatic Programmer, pg. 231</cite>
Whenever I have to repeat a task I usually write a quick script for it. I like to use the right tool for the job, and quite often that’s Bash. In a world where Python and Ruby (et al.) are infinitely trendier I make no apologies for this – when you just want to string together a few Unix commands a shell script beats them hands down (simplicity is a beautiful thing).
The articles that follow cover scripts that might be of use to a wider audience. Here’s hoping that you find something in here that’s useful…
Articles on Automation
Optimising PNG images for the web
Stoyan Stefanov has recently written an interesting series of articles on optimising image files for the web. In his latest article he shows how to use pngcrush to safely shrink your files, one file at a time:
$ pngcrush -rem alla -brute -reduce src.png dest.pngThis evening I found myself wanting to repeat that command for all the PNG files in my current directory, and then (having reviewed the new images) overwrite the originals. Rather than do it by hand I did what all pragmatic programmers do these days, and wrote a script. Here it is in action:
$ pngcrushall
Crushing test4012.png ... ok
Crushing test9200a.png ... ok
Crushing test9200b.png ... ok
Overwrite original files? (y/N) y
Overwriting test4012.png ... ok
Overwriting test9200a.png ... ok
Overwriting test9200b.png ... okYou can get it from github – download pngcrushall.
Obviously you’ll need to install pngcrush too. On a Mac this is pretty easy with MacPorts:
$ sudo port install pngcrush
Integration Testing for Multiple Web Applications
I’ve recently been developing a Rails app that relies on a database that is maintained by another team as part of a different application. As you can imagine, unexpected changes to the database schema can bring our Rails app to it’s knees if they’re deployed to the live server before our application is updated.
Easy git-svn for Rails (or "git-me-up")
I’ve been trying to persuade git-svn to work properly with Rails plugins that are installed via svn:externals. Whilst working out how to do it I stumbled across several great articles, but I couldn’t get any of the solutions presented to work perfectly. Samuel Tesla’s article is especially informative, but for a long time I couldn’t stop git-svn from trying to commit Git metadata back into my Subversion repository…
After a bit of head scratching I got it sorted, and wrapped the process up in a little utility called git-me-up.
Automate your sysadmin with adl
I used to work for a company that was in the business of deploying laptops running Linux into hospitals. We automated the installation of these laptops to such a degree that all we had to do build a new laptop was unwrap it, plug it into an ethernet network and turn it on. We used PXE boot and our own bespoke deployment system to achieve it. It even supported deploying automatic configuration updates over a mobile phone connection, while the laptops were in a different country.
It never seems to be worth going to the effort to setup a tool like puppet when configuring a new desktop computer, a virtual server to run your blog, or a VPS for a small client who is keen to keep the budget down. But why should automation be expensive?
If you like the idea of an automated server build on the cheap, read on…