The beauty of shell scripting
George Malamidis, June 7th, 2006Ah, bash… There has never been a time when I haven’t had fun writing shell scripts. Funny syntax aside, shell scripting is one of the most powerful tools available out there. So little code can do so much with such visible impact that few things compare to it when it comes to putting down little dirty hacks that are going to keep on running on the server for all eternity until you don’t even remember they’re there, or why you wrote them, or if it was you who wrote them in the first place. And no-one will ever complain, either.
‘How come you remembered shell scripting all of a sudden?’ one might ask… For one, I never actually stopped writing shell scripts, because nothing beats them for harnessing a Linux horse with little grief or trouble. Also, I had to write some back-up routine for work the other day… Ultimately it took two #!/bin/bash ten-liners and 3 lines of crontab entries to create an automated procedure which periodically backs up a noticeably large Subversion repository and a few instances of Trac wikis.
What impresses me about those 30 odd lines of code is the number of technologies they interoperate with and the way they integrate those so gracefully.
Programming languages: C (all the Linux programs and commands used), Python (Trac) and Java (the actual code in the Subversion repository).
Operating Systems: Linux (the source server), Window$ (destination file server – don’t ask why, I don’t know either).
Technologies: Archiving (tar), compression (gzip), databases (Sqlite and Berkeley DB), samba (smbclient copies the archives to the file server), or more broadly, inter-op networking.
And I bet I could come up with more, but it’s late and you get the picture anyway… The important observation is that during the whole process the disparity of the systems in question was hardly an issue at all.
One thing that deserves special mention is the hotcopy functionality offered both by Subversion and Trac. It makes life so much easier and works really well under the conditions I’ve tried it on. It is also quite safe, as both freeze/lock the database when backing themselves up to avoid nasty surprises.
