0

私はそのようなbashスクリプトに取り組んでいます。アイデアは、mysql ユーザー、データベースを作成し、新しく作成されたデータベースに対してこのユーザーにすべての権限を付与するスクリプトを作成することです。

    SED=`which sed`
CURRENT_DIR=`dirname $0`

if [ -z $1 ]; then
    echo "No domain name given"
    exit 1
fi
DOMAIN=$1

# check the domain is valid!
PATTERN="^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$";
if [[ "$DOMAIN" =~ $PATTERN ]]; then
    DOMAIN=`echo $DOMAIN | tr '[A-Z]' '[a-z]'`
    echo "Creating hosting for:" $DOMAIN
else
    echo "invalid domain name"
    exit 1 
fi

   echo "Do you want to create MySQL DB for Website (Y/n)?"
read CREATEDB

if [[ ( $CREATEDB == "y" ) || ( -z "$CREATEDB" ) ]]; then
    echo "Enter MySQL root login (leave blank for default value - root):"
    read MYSQLLOGIN 
    if [ -z "$MYSQLLOGIN" ]; then
        MYSQLLOGIN="root"
    fi
    echo "Enter MySQL root PASS:"
    read MYSQLROOTPASS
    if [ -z "$MYSQLROOTPASS" ]; then
        echo "No way without pass"
        exit 1
    fi
    echo "Enter DB name (leave blank for default value - username_db):" 
    read MYSQLDB
    if [ -z "$MYSQLDB" ]; then
        MYSQLDB=$USERNAME"_db"
    fi
    echo "Enter password for newly created MySQL user (!ONLY if you have pwgen - sudo apt-get install pwgen! leave blank for auto password creation):"
    read MYSQLPASS
    if [ -z "$MYSQLPASS" ]; then
        MYSQLPASS=$(pwgen -acn 10 1)
    fi
    mysql -h localhost -u $MYSQLLOGIN -p$MYSQLROOTPASS;
    mysql> CREATE USER $USERNAME@'localhost' IDENTIFIED BY $MYSQLPASS;
    mysql> create database $MYSQLDB;
    mysql> grant usage on *.* to $USERNAME@localhost identified by $MYSQLPASS;
    mysql> grant all privileges on $MYSQLDB.* to $USERNAME@localhost ;
else
exit 1
fi

echo -e "\nSite Created for $DOMAIN with PHP support\n Domain: "$DOMAIN"\n MySQL DB Name: "$MYSQLDB"\nMySQL Username : Pass"$USERNAME" : "$MYSQLPASS ;

私は何を間違っていますか?次のエラーが発生します:

ここに画像の説明を入力

4

2 に答える 2