Creating databases and users with uapi
Hi,
I am using uapi in a bash script to create for a given Cpanel user a database and a user for that database.
The first two commands work fine but the last one always give two kinds of errors:
or instead of user argument, sometimes it says database argument instead of the user argument. Funny thing is that after running that very same command separately in the command line, randomly it works, randomly it shows any of the two aforementioned errors.
/usr/bin/uapi --user=$CPUSER --output=json Mysql create_database name=$DATABASE/usr/bin/uapi --user=$CPUSER --output=json Mysql create_user name=$USERNAME password=$PASSWORD/usr/bin/uapi --user=$CPUSER Mysql set_privileges_on_database user=$USERNAME database=$DATABASE privileges=ALL PRIVILEGES
The first two commands work fine but the last one always give two kinds of errors:
func: set_privileges_on_database
module: Mysql
result:
data: ~
errors:
- (XID 9p7vx9) Provide the "user"argument.
messages: ~
metadata: {}
status: 0
or instead of user argument, sometimes it says database argument instead of the user argument. Funny thing is that after running that very same command separately in the command line, randomly it works, randomly it shows any of the two aforementioned errors.
-
Sorry, the editor put wrong the lines in my script /usr/bin/uapi --user=$CPUSER --output=json Mysql create_database name=$DATABASE /usr/bin/uapi --user=$CPUSER --output=json Mysql create_user name=$USERNAME password=$PASSWORD /usr/bin/uapi --user=$CPUSER Mysql set_privileges_on_database user=$USERNAME database=$DATABASE privileges=ALL PRIVILEGES
BTW, I have WHM 60 build 250 -
Hello, I was able to reproduce this behavior, and it appears related to the URI encoded value for "ALL PRIVILEGES". When reproducing the error message using the example you provided, I notice through strace that it's sometimes attempting to run the command with the wrong syntax: 703657 execve("/usr/bin/uapi", ["/usr/bin/uapi", "--user=user01", "Mysql", "set_privileges_on_database", "user=dbuser123", "database=1234", "privileges=ALL", "PRIVILEGES">, [/* 24 vars */]) = 0
I updated the command to include "%20" instead of the space:/usr/bin/uapi --user=$CPUSER Mysql set_privileges_on_database user=$USERNAME database=$DATABASE privileges=ALL%20PRIVILEGES
I could no longer reproduce the issue after making this change. Could you verify if that addresses the issue? If so, I'll open an internal case to ensure this is updated on our documentation. Thanks!0 -
Yes, it works! Many thanks for looking into this! 0 -
Yes, it works! Many thanks for looking into this!
I'm happy to see that helped. I opened a case with our Documentation Team to ensure the document is updated to further clarify the URI-encoded requirement. Thank you.0
Please sign in to leave a comment.
Comments
4 comments