TOM ARM
TOM ARM

Reputation: 51

DirecAdmin custom script | Insert sample database from url

Custom Bash Script in DA:

/directadmin/scripts/custom/domain_create_post.sh

Below code:

SET UP DATABASE VARIABLES

dbpass=$(openssl rand -base64 12) > /dev/null
ext=$(openssl rand -hex 2) > /dev/null
dbuser="wp${ext}"    # do not include the username_ for dataskq here as DA adds this
wpconfigdbuser="${username}_wp${ext}"
wpadminpass=$(openssl rand -base64 14) > /dev/null

CREATE DATABASE

/usr/bin/mysqladmin -uda_admin -p$(cat /usr/local/directadmin/conf/mysql.conf | grep pass | cut -d\= -f2 ) create ${wpconfigdbuser};
echo "CREATE USER ${wpconfigdbuser} IDENTIFIED BY '${dbpass}';" | mysql -uda_admin -p$(cat /usr/local/directadmin/conf/mysql.conf | grep pass | cut -d\= -f2 );
echo "GRANT ALL PRIVILEGES ON ${wpconfigdbuser}.* TO ${wpconfigdbuser} IDENTIFIED BY '${dbpass}

DOWNLOAD AND INSERT SAMPLE TABLE TO CRATED DATABASE

mysql -u '.dbuser.' -p'.dbpass.' '.dbuser.' table_name < website.com/get/file.sql

I get result: enter image description here

Number of users: 0 Size: 0b

Please can anyone help me check this code?

Upvotes: 0

Views: 98

Answers (1)

Ramon Fincken
Ramon Fincken

Reputation: 291

You are better off using the DA API calls. That way your script will keep working later on.

Upvotes: 0

Related Questions