And now, about my day…
The day started off with some nasty AT&T backbone issues, one of which managed to convince me that my web and mail server was down for a while this morning because ICMP was getting through just fine yet I couldn’t make a TCP connection to save my life. After the relief of finding out most people could get to it just fine I’ve gone on to have a great day, though…
A friend and coworker, whom I’ve mentioned before, has been working on a script to create some SLA reports. SLA stands for service level agreement. You know, the kind of contract you give your customers that says “we guarantee you 99.9% uptime or you can beat us up and take our lunch money.” Anyway, he had two scripts written, a perl script and a shell script, totaling 14 lines. I told him there was room to make the scripts more efficient, but he said it would take a lot of extra lines of code.
I told him I didn’t think it would. In fact, I bet I could make the changes and end up with less lines of code than he currently had. He started counting lines and said there was no way.
“Bet me,” I said.
“No way, you can’t do it in less,” he replies.
“Bet me!” I insisted.
“You’re not gonna count my whitespace and comments, are you?” he stated, obviously intrigued.
“Of course not. No tricks, just bet me.”
“OK, what are the stakes?”
“How about the loser buys the winner lunch?”
“You’re on.”
Silly, silly man. I’ll take that lunch with extra groveling. ;) Here’s the final product, which ended up as 7 lines (we counted lines as lines ending with a semicolon, which constitutes the end of a perl statement). It’s a little dirtier than I would have liked, but pretty elegant considering what we had to work with:
#!/usr/bin/perl -w
use DB_File;open (DATA, 'zcat /var/log/cacti/archive/cacti-output.log.2003-02* | ') ||
die "can't open logs!\n";
dbmopen (%RESULTS, 'results.dbm', 0666);
dbmopen (%RESULTSNU, 'resultsnu.dbm', 0666);
while (<DATA>) {
/\/usr\/local\/www\/cacti\/rra\/([^\s]+)/ && $RESULTS{"$1"}++;
/\/usr\/local\/www\/cacti\/rra\/([^\s]+).+N:U/ && $RESULTSNU{"$1"}++;
}while ($key = each(%RESULTS)) {
print "$key = $RESULTS{$key} " . ($RESULTSNU{$key} || 0) . " " .
(($RESULTS{$key} - ($RESULTSNU{$key} || 0)) / $RESULTS{$key} *
100). "%\n";
}Of course, he hates me now.
Jeremy McMasters III:
Never underestimate NEO, just bug him while he is writing it ;)
February 20, 2003, 2:09 pmSticks:
Always remember:
http://erniesucks.jeffpeck.us
February 20, 2003, 4:03 pmNeo:
Ah yes, I miss that old flash you made… When did you actually do work, Jeff? :-p
VIVA LA CHINCHILLA OF DESTRUCTION!!!
February 20, 2003, 4:12 pmjoni51:
Speaking of when people actually do work….when exactly was this page made, Ernie???? :)
February 20, 2003, 4:22 pmtheTom:
So where is the code for “GOTO 10″?
Yeah seems these days making a bet is too risky but then a dinner is a dinner
February 20, 2003, 6:39 pmfubabee:
hahahah! funny!… well i think that Ernie Rocks!
February 20, 2003, 7:36 pmBrashBrazen:
Jeff/Ernie, how do you guys manage to do nothing at work, get paid, and nobody finds out? I need to wield this power!!!! Teach me your ways!!!
VIVA JAY SHERMAN!!!! VIVA QUEBEC!!!
March 18, 2003, 12:13 am