VICIDIAL test lead generator
Posted: Sun Jan 21, 2007 1:29 pm
I wrote this bash script to generate random test leads for VICIDIAL and insert them into the DB. Currently it needs to be run on the system hosting the DB. When I get some free time I plan to add an option to connect to the DB remotely.
It normally generates 555 numbers (in asterisk the NXX55501XX range) which should be fake numbers under NANP. With the -r option it will create real numbers under NANP (be careful with this option as there is no Do-Not-Call srubbing in the script). It also checks that the phone number is not in the Caribbean, Canada, or a 900 number.
Currently it creates a temporary file to hold the SQL insert statements so that only one DB connection needs to be opened, which is why it limits you to 100000 leads. I do not know of any way to get around this in bash. I may redo this in perl if I find myself with a bunch of free time on my hands so as to overcome this.
Be very careful how you use this script. If you choose to use it, I am not responcible for any charges on your phone bill, or fines that you incure. I plan on using this on a test dialer that is hooked up to a second asterisk box that fakes the phone system.
ranlead.sh:
If anyone can see some areas of improvement, or can think of any other area codes that are not a wise idea to dial within the US, please let me know.
It normally generates 555 numbers (in asterisk the NXX55501XX range) which should be fake numbers under NANP. With the -r option it will create real numbers under NANP (be careful with this option as there is no Do-Not-Call srubbing in the script). It also checks that the phone number is not in the Caribbean, Canada, or a 900 number.
Currently it creates a temporary file to hold the SQL insert statements so that only one DB connection needs to be opened, which is why it limits you to 100000 leads. I do not know of any way to get around this in bash. I may redo this in perl if I find myself with a bunch of free time on my hands so as to overcome this.
Be very careful how you use this script. If you choose to use it, I am not responcible for any charges on your phone bill, or fines that you incure. I plan on using this on a test dialer that is hooked up to a second asterisk box that fakes the phone system.
ranlead.sh:
- Code: Select all
#!/bin/bash
# ranlead.sh VERSION 0.3
#
# Inserts into VICIDIAL leads with a random phone number
#
# Copyright (C) 2007 Michael Cargile, Explido Software USA, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Because this script creates a temp file to hold the sql statements before
# running them against the DB there is a max lead constraint to prevent the
# temp file from getting huge. This can be overridden if desired with the -M
# option. Just ask yourself though "Do I need really more than 100000 leads
# for test purposes?"
MAXLEADS=100000
DATE=`date +%G-%m-%d`
FILE="/tmp/`basename $0``date +%s`"
VERSION="0.3"
NUMLEADS=""
USER=""
PASSWORD=""
LISTID=""
REALLEADS="FALSE"
HELP="FALSE"
VERBOSE="FALSE"
ALLOWPASTMAX="FALSE"
while getopts ":n:u:p:l:rhvM" Option
do
case $Option in
n) NUMLEADS=$OPTARG;;
u) USER=$OPTARG;;
p) PASSWORD=$OPTARG;;
l) LISTID=$OPTARG;;
r) REALLEADS="TRUE";;
h) HELP="TRUE";;
v) VERBOSE="TRUE";;
M) ALLOWPASTMAX="TRUE";;
esac
done
shift $(($OPTIND - 1))
if [ "$HELP" == "TRUE" ]
then
echo "`basename $0` version $VERSION"
echo "Usage: `basename $0` options (-nMuplrhv)"
echo "-nNUMLEADS where NUMLEADS is the number of leads"
echo "-M is switch to allow more than $MAXLEADS leads to be generated (may cause problems)"
echo "-uDBUSERNAME where DBUSERNAME is the username for the VICIDIAL DB"
echo "-pDBPASSWORD where DBPASSWORD is the password for the VICIDIAL DB"
echo "-lLISTID where LISTID is the id of the list you are creating"
echo "-r is a switch to create real numbers instead of 555 numbers"
echo "-h displays this help message"
echo "-v switches on verbose mode"
exit 0
fi
if [[ "$ALLOWPASTMAX" == "FALSE" && "$NUMLEADS" -ge $MAXLEADS ]]
then
echo "TOO MANY LEADS REQUESTED"
echo "use -M if you wish to go past $MAXLEADS"
echo "USE -M AT YOUR OWN RISK"
exit 1
fi
if [ "$ALLOWPASTMAX" == "TRUE" ]
then
echo "ALLOWPASTMAX is enabled!!!"
echo "Good luck."
fi
if [ "$NUMLEADS" == "" ]
then
#get the number of leads
echo -n "Enter number of leads: "
read NUMLEADS
fi
if [ "$LISTID" == "" ]
then
#get list id for this list
echo -n "Enter the list id: "
read LISID
fi
if [ "$USER" == "" ]
then
#get the username to connect to the DB
echo -n "Enter DB username: "
read USER
fi
if [ "$PASSWORD" == "" ]
then
#get the password to connect to the DB
echo -n "Enter DB password: "
read -s PASSWORD #-s to hide the output
echo ""
fi
if [ "$VERBOSE" == "TRUE" ]
then
echo ""
echo -n "Generating leads."
fi
COUNT=1
NUMBER=0
REST=0
ADDITION=0
AREACODE=0
while [ "$COUNT" -le $NUMLEADS ]
do
if [ "$VERBOSE" == "TRUE" ]
then
echo -n "."
fi
let "COUNT += 1"
# make sure we are not calling the carribiean, canada, or 900 numbers
BADAREA="TRUE"
while [ "$BADAREA" == "TRUE" ]
do
AREACODE=$RANDOM
let "AREACODE %= 800"
let "AREACODE += 200"
case $AREACODE in
809) BADAREA="TRUE";; # Carribiean
441) BADAREA="TRUE";;
787) BADAREA="TRUE";;
340) BADAREA="TRUE";;
670) BADAREA="TRUE";;
671) BADAREA="TRUE";;
939) BADAREA="TRUE";;
684) BADAREA="TRUE";;
403) BADAREA="TRUE";; # Canada
780) BADAREA="TRUE";;
204) BADAREA="TRUE";;
709) BADAREA="TRUE";;
289) BADAREA="TRUE";;
416) BADAREA="TRUE";;
519) BADAREA="TRUE";;
613) BADAREA="TRUE";;
647) BADAREA="TRUE";;
705) BADAREA="TRUE";;
807) BADAREA="TRUE";;
905) BADAREA="TRUE";;
306) BADAREA="TRUE";;
250) BADAREA="TRUE";;
604) BADAREA="TRUE";;
778) BADAREA="TRUE";;
506) BADAREA="TRUE";;
902) BADAREA="TRUE";;
418) BADAREA="TRUE";;
450) BADAREA="TRUE";;
514) BADAREA="TRUE";;
819) BADAREA="TRUE";;
867) BADAREA="TRUE";;
900) BADAREA="TRUE";; # toll numbers
*) BADAREA="FALSE";;
esac
done
ADDITION=$RANDOM
if [ "$REALLEADS" == "FALSE" ]
then
#5550100 through 5550199 are fictitious
REST="5550100"
let "ADDITION %= 100"
let "REST += ADDITION"
NUMBER="$AREACODE$REST"
else
#2000000 through 9999999 are real excluding 5550100 through 5550199
NUMBER="5550100"
while [[ "$NUMBER" -ge "5550100" && "$NUMBER" -le "5550199" ]]
do
REST="2000000"
let "ADDITION %= 8000000"
let "REST += ADDITION"
NUMBER="$AREACODE$REST"
done
fi
echo "insert into asterisk.vicidial_list values('','$DATE','','NEW','','','TEST01','$LISTID','TESTCAMP','N','1','$NUMBER','Mr','JOHN','H','SMITH-$COUNT','$RANDOM Fake St.','','','Clearwater','FL','','33760','USA','M','1970-01-01','','test@test.com','suprise','comments go here','0');" >> $FILE
done
if [ "$VERBOSE" == "TRUE" ]
then
echo ""
echo ""
echo "Inserting leads into the database."
fi
mysql -u $USER --password=$PASSWORD -e "\. $FILE"
if [ "$VERBOSE" == "TRUE" ]
then
echo "Cleaning up."
fi
rm $FILE
If anyone can see some areas of improvement, or can think of any other area codes that are not a wise idea to dial within the US, please let me know.