user_create_post.sh Reseller

Groen01

Verified User
Joined
May 7, 2009
Messages
7
Hello guys,

I've got a little problem using user_create_post.sh. When a user is created I want a database created and sql file inserted. I use the following user_create_post.sh and it works:
Code:
# Read DA mysql connection
DA_MYSQL=/usr/local/directadmin/conf/mysql.conf
DA_USER=`cat $DA_MYSQL | grep user= | cut -d= -f2`
DA_PASS=`cat $DA_MYSQL | grep passwd= | cut -d= -f2`

NEW_DB="${username}_database"
NEW_USER="${username}@localhost"

# create database
mysql -u $DA_USER -p$DA_PASS --execute="CREATE DATABASE $NEW_DB"

#create user
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"

#create default user
NEW_USER="${username}_usr@localhost"
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"

#create default layout
mysql -u$DA_USER -p$DA_PASS $NEW_DB < /home/sql.sql

Now we have different resellers so some of the resellers wants a different sql file inserted.
I made the following script
Code:
#!/bin/sh

creator=`grep creator /usr/local/directadmin/data/users/${username}/user.conf | cut -f2 -d"="`

DA_MYSQL=/usr/local/directadmin/conf/mysql.conf
DA_USER=`cat $DA_MYSQL | grep user= | cut -d= -f2`
DA_PASS=`cat $DA_MYSQL | grep passwd= | cut -d= -f2`

NEW_DB="${username}_database"
NEW_USER="${username}@localhost"

# create database
mysql -u $DA_USER -p$DA_PASS --execute="CREATE DATABASE $NEW_DB"

#create user
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"

#create default user
NEW_USER="${username}_usr@localhost"
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"

if [ "$creator" = "reseller" ]; then

#create default layout
mysql -u$DA_USER -p$DA_PASS $NEW_DB < /home/reseller.sql

fi

This doesn't work. When I change the creator to creator='reseller' it works. Can somebody help me out?
 
Hello,

I did some tests and it seems to be that the file user.conf is created to late so the script can't grep the creator.

Does somebody know a solution?
 
Hello,

Delete this line to fix it:
Code:
creator=`grep creator /usr/local/directadmin/data/users/${username}/user.conf | cut -f2 -d"="`
The $creator variable should already be there, filled in the environment.

John
 
Hello John,

Thanks that works!!!

Where can i find all the filled in variables?
 
Back
Top