[RESOLVED] stuck on a email verification script

Hello everyone,

I am still working on my WordPress installation script. I am trying to ask the users to type the administrator email address two times and do a check on it. At the moment I am stuck at line 22. How do I get the script to ask to type the email again and perform the check to see if the email is formatted correctly?

I think that my script can also be simplified/compressed. Please feel free to comment if you have any advice for me (I am in process of learning shell scripting). The block of code is below.
Code:
1 #!/bin/sh
2 #
3
4 read -p "Enter email : " e
5 echo "$e" | grep '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$'
6 while [ $? -eq 1 ]; do
7  echo "Error: Enter a valid email address"
8  read -p "Enter email : " e
9  echo "$e" | grep '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$'
10 done
11
12 read -p "Confirm email : " e2
13 echo "$e2" | grep '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$'
14 while [ $? -eq 1 ]; do
15 	echo "Error: Enter a valid email address"
16 	read -p "Enter email : " e2
17 	echo "$e" | grep '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$'
18 done
19
20 if [ $e!=$e2 ]; then
21 echo "Email adress doesn't match!"
22 ????
23 fi

My other question is about database connection. In a normal scenario, I would do the following to create the database via a script (username and password saved in the ~/.my.cnf file):
Code:
# Create the database
/usr/bin/mysql -e "CREATE DATABASE $db_name"
/usr/bin/mysql -e "GRANT ALL PRIVILEGES ON $db_name.* to '"$db_user"'@'localhost' IDENTIFIED BY '"$db_password"';"

My problem is that the database is in a different jail on the same host. Any idea how do can I create a remote connection to create the new WordPress database?

Thank you all.

Fred
 
Re: stuck on a email verification script

Something like the following should work.

Code:
#!/bin/sh
dbuser=myuser
dbpass=mypass
dbhost=1.2.3.4

email1() {         
    read -p 'Enter email: ' e
          
    while [ `echo $e | grep -c '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$'` = "0" ]; do
        read -p 'Enter email: ' e
    done
}

email2() {         
    read -p 'Enter email again: ' e2

    while [ `echo $e2 | grep -c '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$'` = "0" ]; do
        read -p 'Enter email again: ' e2
    done
}

email1
email2

while [ "$e" != "$e2" ]; do
    echo
    echo "Emails do not match"
    echo
    email1
    email2
    
done

/usr/bin/mysql -u$dbuser -p$dbpass -h$dbhost -s -e "CREATE DATABASE $db_name"
/usr/bin/mysql -u$dbuser -p$dbpass -h$dbhost -s -e "GRANT ALL PRIVILEGES ON $db_name.* to '"$db_user"'@'localhost' IDENTIFIED BY '"$db_password"';"

echo
echo "Done."
echo
 
Re: stuck on a email verification script

This one checks if they match then checks if it's valid.

Code:
#!/bin/sh
#
EMAIL=""
COMFIRM_EMAIL=""

while true; do
    ## Read input
    read -p "Enter email   : " EMAIL
    read -p "Comfirm email : " COMFIRM_EMAIL

    ## Do they match?
    if [ "$EMAIL" != "$COMFIRM_EMAIL" ]; then
        echo "These email addresses don't match. Try again?"
        continue;
    fi

    ## Is it a valid email address?
    echo "$EMAIL" | grep '^[a-zA-Z0-9]*@[a-zA-Z0-9]*\.[a-zA-Z0-9]*$' >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo "Email address isn't valid. Try again?"
        continue;
    fi

    ## Done
    break;
done

echo "Do something with \$EMAIL"
 
Re: stuck on a email verification script

Wow guys,

Thank you very much :) I just learn even more ways of doing the same thing as you both described two different methods :)

Thank you so much.
 
Re: stuck on a email verification script

You can use jexec() to create the database if you're not in a jail. Or set[]up ssh()/sshd() and use that.

Code:
jexec database_jail_name /usr/bin/mysql -e "CREATE DATABASE $DB_NAME"
jexec database_jail_name /usr/bin/mysql -e "GRANT ALL PRIVILEGES ON $DB_NAME.* to '"$DB_USER"'@'localhost' IDENTIFIED BY '"$DB_PASSWORD"';"
 
Re: stuck on a email verification script

Toast said:
You can use jexec() to create the database if you're not in a jail. Or set up ssh()/sshd() and use that.

Code:
jexec database_jail_name /usr/bin/mysql -e "CREATE DATABASE $DB_NAME"
jexec database_jail_name /usr/bin/mysql -e "GRANT ALL PRIVILEGES ON $DB_NAME.* to '"$DB_USER"'@'localhost' IDENTIFIED BY '"$DB_PASSWORD"';"

The script will be run from inside my web server jail, so I don't think I could use that code.
Good to know to future project tough
 
Back
Top