'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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ramon Fincken