Chronophage.net Blog

Tag: Programming

What happens when I program “On the Fly”

by Nick on Jun.11, 2009, under News, Sofware

Don Hertzfeld?So I needed a quick script to query a billing database for DSL users. The user names, of course where horribly inconsistent. I had to use a program that executed a query of the database, as I didn’t have access to the actual database. Oh, and I didn’t know any Perl at the time.

Now, I have a bad habit when writing code for myself, to use ambiguous variable names, and strange loop structures, and no comments. See if you can figure out what’s going on.

Oh, I vow never to write code like this again. ;)

#!/bin/bash

echo Audit run on $( date )
echo Audit run on $( date ) > notinbilldb.txt
echo
echo

for i in $( cat radiusdump.txt | awk '{print $1}' ); do
 	t2=""
	t2=$( echo $i | sed -e 's/\@.*$//;' | cut -f1 -d . )
	t1=$( billdb -s $t2 | grep DSL | awk '{print $3}' | sed -e 's/\.dsl//; s/^dsl//;s/\@.*$//;' )
  	t3="0"
	t4="0"
	t5="0"
	t6=""

	if [ "$t1" = "" ]; then
		t1=$( billdb -s $i | grep Email | awk '{print $3}' | sed -e 's/\@.*$//;' )
		t5="1"
	fi

	if [ "$t1" = "" ]; then
		echo $i is not in billdb.
		echo $i is not in billdb. >> notinbilldb.txt
		t4="1"
	fi
	p=$( echo $i | sed -e 's/\.dsl//; s/^dsl//;s/\@.*$//;' )
	k=""

	for k in $( echo $t1 ); do
		if [ "$p" = "$k" ]; then
			if [ "$t5" = "1" ]; then
				t6=", but only in email"
			fi
			echo $i matched $k in billdb$t6.

			t3="1"
	 	fi
	done
	if [ "$t4" = "$t3" ]; then
		echo $i is really not in billdb but was close to $t1.
        	echo $i is really not in billdb but was close to $t1. >> notinbilldb.txt
	fi
	echo --------------------------------
	echo
done
echo
echo Audit completed $( date )
echo
Leave a Comment :, , , , more...

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...