Friday, August 31, 2007

Unix Shell, and other flavors of, Scripting

Okay, everybody that remembers using MS-DOS raise your hands. Not really that many of us, are there? And who uses a command line interface these days? Well, I do.

That's the thing about being a maintenance programmer who loves being a generalist, I get into a wide range of things. One of them being support for an application that displays invoices, and other reports, downloaded from one of those big iron dinosaurs, a mainframe, to an Oracle database on a Unix server. These reports are stored in such a way that the customers select them, on a web page, by the customer number, report type, and date; then, they're converted to PDF format for the customer to look at, treasure, save locally, print, or ignore. I just implemented a new report feed, which meant a new download file and a new load into Oracle. And that meant an adventure in Unix shell scripting. I guess, to be precise, I should say AIX shell scripting, using the Korn shell, not the C shell, Bourne shell, or even the Bourne Again shell.

Honestly, I love scripting languages. That was what was so much fun when I started web development. Microsoft's coding model at the time was ASP, where the HTML, Javascript for client-side processing, and VBScript for server-side processing were all stored together in the same ASP file, just waiting for a user request to come in, data to be grabbed off of a database, the whole thing turned into HTML for the browser to interpret, and we're off to the races with a dynamic web page. The cool thing, for the geek in me, was the immediate response, where I could quickly find out what syntax errors and logic bugs I had subtly embedded in my code. Then, I could spend hours diagnosing and fixing! Nerd nirvana...

Unix shell scripting, that's where I was. If you ever thought DOS commands were cryptic, you ain't seen nothing yet. Isn't it perfectly obvious that find . -mtime +30 -exec rm -f {} \; will delete all files in the current directory that were modified, which includes created, over 30 days ago? No? It wasn't to me, either. And I haven't even touched grep or sed. Google is my friend. Sometimes, though, Dogpile is even better.