Sunday, May 20, 2007

Automate Everything!

The other day, while waiting for another computer reboot or something similar, I grabbed The Pragmatic Programmer from the shelf. I already read the book, so I was just quickly browsing the tips in the book when I found this one: "Automate Everything". (you can find it by looking for "Don't Use Manual Procedures" in the previous link).

I already do this at work, but I started thinking it would be a really good idea to start applying this principle to my home projects. Take my sister's in law website. Here's the procedure I use to upload it to the server:
  1. Open googleanalytics.txt and copy the contents
  2. Open pageend.php and paste googleanalytics.txt content
  3. Open gFTP
  4. Open KeePassX to fetch the site's password
  5. Use gFTP to transfer some of the directories in the development folder (this actually counts as about 10 steps!)
  6. Check if I didn't make a mistake in the gFTP 10 steps!
  7. Open pageend.php and remove googleanalytics.txt content
Some notes on these procedures: I never did steps 1, 2 and 7. It was too much work so I never actually got Google Analytics to work until yesterday. I'm not kidding about step 5 being about 10 steps... I actually uploaded the folders one by one to make sure I got all the right files and that the .svn folders weren't copied. This may seem rather stupid, but since I executed this procedure about once a month it wasn't really a problem, just a nuisance.

Still I decided to automate everything. I did a shell script and right now I have a one step procedure to upload the site:
  1. Run ./publish.sh
And what did I gain with this 2 hour or so investment?
  1. I learned more about bash programming
  2. I learned how sed works
  3. I learned about wput
  4. I got Google Analytics working on the website
  5. I'll be doing no more mistakes while uploading the site
  6. I can make small changes to the site without thinking about the dreaded upload process
  7. I feel like a better geek! :)

1 comment:

LY said...

Have you tried rsync with ssh?

Simply send your ssh public key to the remote server, then rsync everything over:

rsync -avile 'ssh' allthisstuff/* username@removeserver.org:~