Mail relay stress test
I was asked by one of our email administrators to create a "mail relay
stress test" script. The administrator wanted to be able to run a script
that would send out email with the following probabilities:
27% chance of sending a 37,597 byte message with an attachment
17% chance of sending a 3,075 byte message
16% chance of sending a 7,108 byte message
10% chance of sending a 14,743 byte message
6% chance of sending a 547 byte message
6% chance of sending a 60,969 byte message with an attachment
4% chance of sending a 124,167 byte message with an attachment
3% chance of sending a 85,993 byte message with an attachment
2% chance of sending a 171,358 byte message with an attachment
2% chance of sending a 221,826 byte message with an attachment
1% chance of sending a 274,007 byte message with an attachment
1% chance of sending a 313,479 byte message with an attachment
1% chance of sending a 416,983 byte message with an attachment
1% chance of sending a 550,839 byte message with an attachment
1% chance of sending a 761,659 byte message with an attachment
1% chance of sending a 1,214,991 byte message with an attachment
1% chance of sending a 5,505,014 byte message with an attachment
The administrator provided me with the attachments as Word document files.
For messages without an attachment, I created the message bodies using Linux's
/dev/urandom device.
dd if=/dev/urandom of=3075_byte_msg bs=1 count=3075
dd if=/dev/urandom of=7108_byte_msg bs=1 count=7108
dd if=/dev/urandom of=14743_byte_msg bs=1 count=14743
dd if=/dev/urandom of=547_byte_msg bs=1 count=547
The administrator wanted to send MIME attachments instead of uuencoded
attachments. Fortunately, the mutt e-mail
client can send MIME attachments non-interactively.
Both the ksh and bash shells contain a special variable RANDOM to generate
a random number between 0 and 32767. In my case, I want to generate a random
number from 1 to 100 using the following syntax:
echo $(( RANDOM % 100 + 1))
Since the script will be running on a Solaris system, I'll use ksh instead
of bash when writing the script.
#!/bin/ksh
# No arguments passed to script; echo usage and exit
if [ -z "$1" ] ; then
echo "Usage: $0 number_of_messages"
exit 1
fi
# $MUTT is the absolute path to the mutt MUA
MUTT=/usr/local/bin/mutt
# $RECIPIENTS is a list of email recipients
RECIPIENTS=recipient_email_addresses
COUNTER=0
while [ "$COUNTER" -lt $1 ]
do
RN=`echo $(( RANDOM % 100 + 1))`
if [ $RN -ge 1 -a $RN -le 27 ] ; then
$MUTT -a 37597_bytes.doc $RECIPIENTS <
"."
elif [ $RN -ge 28 -a $RN -le 44 ] ; then
$MUTT -i 3075_byte_msg $RECIPIENTS <
"."
elif [ $RN -ge 45 -a $RN -le 60 ] ; then
$MUTT -i 7108_byte_msg $RECIPIENTS <
"."
elif [ $RN -ge 61 -a $RN -le 70 ] ; then
$MUTT -i 14743_byte_msg $RECIPIENTS <
"."
elif [ $RN -ge 71 -a $RN -le 76 ] ; then
$MUTT -i 547_byte_msg $RECIPIENTS <
"."
elif [ $RN -ge 77 -a $RN -le 82 ] ; then
$MUTT -a 60969_bytes.doc $RECIPIENTS <
"."
elif [ $RN -ge 83 -a $RN -le 86 ] ; then
$MUTT -a 124167_bytes.doc $RECIPIENTS <
"."
elif [ $RN -ge 87 -a $RN -le 89 ] ; then
$MUTT -a 85993_bytes.doc $RECIPIENTS <
"."
elif [ $RN -ge 90 -a $RN -le 91 ] ; then
$MUTT -a 171358_bytes.doc $RECIPIENTS <
"."
elif [ $RN -ge 92 -a $RN -le 93 ] ; then
$MUTT -a 221826_bytes.doc $RECIPIENTS <
"."
elif [ $RN -eq 94 ] ; then
$MUTT -a 274007_bytes.doc $RECIPIENTS <
"."
elif [ $RN -eq 95 ] ; then
$MUTT -a 313479_bytes.doc $RECIPIENTS <
"."
elif [ $RN -eq 96 ] ; then
$MUTT -a 416983_bytes.doc $RECIPIENTS <
"."
elif [ $RN -eq 97 ] ; then
$MUTT -a 550839_bytes.doc $RECIPIENTS <
"."
elif [ $RN -eq 98 ] ; then
$MUTT -a 761659_bytes.doc $RECIPIENTS <
"."
elif [ $RN -eq 99 ] ; then
$MUTT -a 1214991_bytes.doc $RECIPIENTS
< "."
elif [ $RN -eq 100 ] ; then
$MUTT -a 5505014_bytes.doc $RECIPIENTS
< "."
fi
# Increment counter
COUNTER=`expr $COUNTER + 1`
done
Back to brandonhutchinson.com.
Last modified: 01/16/2003