« August 2007 | Main | October 2007 »

September 2007 Archives

September 5, 2007

Another Email Account Milestone

I passed by 200,000 unread messages a couple days ago. At my current rate, I'll have a million within 24 months.

Cool Bash Trick I Didn't Know About

Usually, when I use a for loop in Bash, I do something like:

for USERNAME in $USERNAME_LIST

I found out today that you can also call a for loop without the "in" parameter and it will default to getting the input parameters that are passed to your script in the first place. So, if you want to be able to run your script as:

./my_script.sh username1 username2 username3

each of those usernames can be processed with a for like like:

for USERNAME
do
     echo $USERNAME #Just echo it back out for debugging purposes
done

Common knowledge, I'm sure, but it's new to me and came in super handy today.

September 19, 2007

The Trials and Tribulations of Testing SMTP Authentication From Within Bash

Two really random issues trying to write a command line test to ensure a specified username and password are able to authenticate with our SMTP services. First, here is what my final function ended up being:

test_account_smtp(){
USERNAME="$1"
PASSWORD="$2"
USERNAME_BASE64=`echo "use MIME::Base64;
	print encode_base64('$USERNAME');" | perl`
PASS_BASE64=`echo "use MIME::Base64;
	print encode_base64('$PASSWORD');" | perl`
COUNTER=1
while [ "$RETURN" != "0" ] && [ "$COUNTER" != "20" ]
do
	echo "spawn telnet lb.relay 25
		expect \"220 relay*forbids use of this system for unsolicited bulk electronic mail*\"
		send -- \"EHLO mailinstaller\.emailsrvr\.com\r\"
		expect \"*250 8BITMIME*\"
		send -- \"AUTH LOGIN\r\"
		expect \"*334 .*\"
		send -- \"$USERNAME_BASE64\r\"
		expect \"*334 .*\"
		send -- \"$PASS_BASE64\r\"
		expect \"*Authentication successful*\"
		send -- \"QUIT\r\"
		expect \"*Bye*\"
		expect \"*Connection closed by foreign host*\"
		send -- \"\r\"
		expect eof" | expect >> /var/tmp/SMTP_TEST_$1 2>&1
	cat /var/tmp/SMTP_TEST_$1 >> $DEBUG_LOG
	CHECK=`grep "Authentication successful" /var/tmp/SMTP_TEST_$1`
	if [ -z "$CHECK" ]
	then
		echo '!!!'" Could not open SMTP account $1 with password $2; will try again in ten seconds" | tee $DEBUG_LOG
		COUNTER=$(($COUNTER + 1))
		RETURN=1
		sleep 10
	else
		RETURN=0
		continue
	fi
done
rm -f /var/tmp/SMTP_TEST_$1
return $RETURN
}

Yes, it's messy, but it's messy for a reason -- that's what I had to do to get it to work.

You may be asking, what's with those calls to Perl? Well, it seems that OpenSSL has a function to encode a string in base64 (needed to talk to the SMTP server), however it doesn't work. I was originally getting consistently-incorrect auth information and traced it back to OpenSSL returning different output compared to online base64 encoders and Perl's encode_base64() function. What the heck?!

As for the do/while loop, it was originally a for loop, but then the expect script would get stuck in an infinite loop every time. For whatever reason, replacing the for with a while fixed it. Again, I don't get it, but that's what I had to do to get it working.

If anyone out there knows why these two issues might occur, please do enlighten. I'm most curious, but not enough to go trolling around Google for an answer to an issue I already have a workaround for.

September 25, 2007

Awesome Error Message of the Day

At least it was a successful error...

About September 2007

This page contains all entries posted to NuclearDonkey.net in September 2007. They are listed from oldest to newest.

August 2007 is the previous archive.

October 2007 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34