the joy and pain of refactored shell scripts.

WebDragon on 2003-03-30T06:40:09

Well. My first Journal entry. I wonder what else is going to happen here... :-)

I've gotten somewhat frustrated with the quota warning system that comes with Red Hat 8, and after spending some time looking through the various quota modules and scripts on CPAN and having tracked down a quota_check.sh script from the web, that originated on Solaris, I've decided to go ahead and try and refactor it into Perl, to see what can be made of it.

Partially I'm doing this as an exercise, and to stretch my knowledge somewhat. I'm not a shell-scripter in the slightest so it's going to be interesting, to say the least. [I've already fallen for Randal's sh2perl joke. *sigh* That'll teach me not to read it first. :-)] Just trying to figure out why some of the things were done the way they were, as well as what some of the bizarre bash constructs even mean, is bad enough.

I can easily remove all of the stuff that uses awk, since Perl can do it all internally anyway. That's one hurdle that'll be fairly straightforward to resolve. The hard part is that it (the shell script) seems to have chain-loaded a rather large pipe sequence into a variable, in several different places in the script, all of which include awk and sub-scripts for it.

Separating out the wheat from the chaff and making it look clean and maintainable, making it scalable, and safe... is going to be the really hard part.

Some of the initial prep was fairly easy, thank goodness and little coders who whipped up Getopt::Long. Some of the wild shell case syntax was obviated thanks to this little gem.

Lord only knows where this is going to take me, how long it will take me, and whether or not ultimately it will be generally more useful and pragmatic than what already exists, but it'll be fun finding out. =:)


sh2perl the earliest Perl joke module/script?

oneiron on 2003-03-31T08:16:45

Long before the Acme namespace was mandated, there were a number of joke modules lurking around -- the lovely David H Adler esq's seminal Semi::Semicolons, for instance. Not certain, but I'm pretty sure sh2perl was the first (I heard an earlier incarnation of it emailed tchrist with a request to convert a shell script to perl).