#! Binsh # definethestrctureoftablequot; (usernamechar (50) notnull, passwordchar (20) notnull, uidchar (10) no
#! /Bin/sh # define the strcture of tableTABLE = quot; (username char (50) not null, password char (20) not null, uid char (10) no
#! /Bin/sh
# Define the strcture of table
TABLE = "(username char (50) not null, password char (20) not null, uid char (10) not null, gid char (10) not null, maildir char (100) not null, domain char (20) not null, active char (1) default '1 ');"
# Create database and table
# ++ ++
For type in database table; do
Printf "Please input the $ type name you wowould like to create: [postfix]"
While read data; do
If [! -Z $ {data}]; then
If ["$ type" = "database"]; then
Database = $ data
Elif ["$ type" = "table"]; then
Table = $ data
Fi
Break
Fi
Printf "Please input the database name you wowould like to create: [postfix]"
Done
Done
# ++ ++
# Input the data per user
# ++ ++
For (I = 1; I ++); do
Printf "Do you want to input the data per user: [yes, no]"
While read yes_no; do
If ["$ yes_no "! = "Yes"]; then break 2; fi
Echo "Please input the data of NO. $ I user :"
For col in username password uid gid maildir domain active; do
Printf "$ col of NO. $ I:" & read $ {col} [$ {I}]
Done
Break
Done
Done
# Output the data you input
# ++ ++
Echo ""
Echo "++ ++ ++"
Echo "Please make sure the data you input :"
Echo "Database: $ database"
Echo "Table: $ table"
Echo ""
Echo "Show the recodes you input :"
Echo "username password uid gid maildir domain active"
For (n = 1; n Echo "$ {username [$ n] }$ {password [$ n] }$ {uid [$ n] }$ {gid [$ n] }$ {maildir [$ n] }$ {domain [$ n] }$ {active [$ n]}"
Done
# ++ ++
# Execute the SQL to input data to mysql
# ++ ++
Echo ""
Echo "Executing the SQL to input data to mysql ......"
Printf "Creating database $ database ......"&&\
Mysql-u root-h -- password = RedHat-e "create database if not exists $ {database }"&&\
Echo-e "\ 033 [32mOK \ 033 [m"
Printf "Creating table $ table ......"&&\
Mysql-u root-h -- password = redhat $ database-e "create table if not exists $ {table} $ TABLE "&&\
Echo-e "\ 033 [32mOK \ 033 [m"
# Insert recode to mysql
For (n = 1; n Printf "Insert NO. $ n recode ......"&&\
Mysql-u root-h -- password = redhat $ database-e "insert into $ table values ('$ {username [$ n]}', encrypt ('$ {password [$ n]}'), '$ {uid [$ n]}', '$ {gid [$ n]}', '$ {maildir [$ n]}', '$ {domain [$ n]}', '$ {active [$ n]}') "& \
Echo-e "\ 033 [32mOK \ 033 [m"
Done
# Show all the recode
Echo ""
Echo "Show all the recods in the mysql :"
Mysql-u root-h -- password = redhat $ database-e "select * from $ table"
,