[wplug] Script to import TXT into mySQL
Kevin Squire
gentgeen at linuxmail.org
Thu Jul 26 20:43:58 EDT 2007
I currently have a bash script that will allow my to input a new user
into my mySQL table for the postfix email system. It reads the
necessary 3 variables from the command line with:
echo -n "Mail adress: "
read MAILADRESS
echo -n "Password: "
read PASSWORD
echo -n "Quota: "
read QUOTA
What I need to do is now alter that script so that I can input ~4000
users :-)
I have the info in a text file, and I am thinking of using a counter
with a while loop to read the text file. "the meat" of the original
script will be put into a fuction that gets called during the loop.
Here is the text file:
user1 at example.org
user2 at example.org
user3 at example.org
etc
Here is the basics of the script that I am thinking of using:
function themeat ()
{ assorted stuff here }
# The two default settings
PASSWORD="changeme"
QUOTA="50000000S"
# Find the number of lines in a $parsefile
noline=`wc -l $parsefile | cut -d" " -f1`
# Need to repeat themeat for each row of the $parsefile
x=1 # initalize x for my counter
while [ "$x" -le "$noline" ]; do
MAILADDRESS=`sed ''$x'p $parsefile`
themeat
x=`expr $x + 1` # Increase counter by 1
done
So my question... How can I make sure that MAILADDRESS does not get any
accidental trailing white spaces? I don't want "user1 at example.org "
to go into my database.
also, if anyone has a more elegant way to do this, I would be happy to
hear it :-)
--
http://gentgeen.homelinux.org
#############################################################
Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility
More information about the wplug
mailing list