{"id":215,"date":"2023-06-26T04:36:50","date_gmt":"2023-06-26T04:36:50","guid":{"rendered":"https:\/\/cainhosting.com\/community\/?post_type=ht_kb&#038;p=215"},"modified":"2023-06-26T04:51:14","modified_gmt":"2023-06-26T04:51:14","slug":"directadmin-api-bash-script-to-create-user-account","status":"publish","type":"ht_kb","link":"https:\/\/cainhosting.com\/community\/knowledge-base\/directadmin-api-bash-script-to-create-user-account\/","title":{"rendered":"DirectAdmin bash script to create user account &#038; database."},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-1024x768.jpg\" alt=\"\" class=\"wp-image-225\" title=\"\" srcset=\"https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-1024x768.jpg 1024w, https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-300x225.jpg 300w, https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-768x576.jpg 768w, https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-50x38.jpg 50w, https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-60x45.jpg 60w, https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script-100x75.jpg 100w, https:\/\/cainhosting.com\/community\/wp-content\/uploads\/2023\/06\/da_bash_script.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>Here <a href=\"https:\/\/cainhosting.com\" target=\"_blank\" rel=\"noreferrer noopener\">CainHosting <\/a>has created a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Bash_(Unix_shell)\" target=\"_blank\" rel=\"noreferrer noopener\">bash script<\/a> to work with the <a href=\"https:\/\/www.directadmin.com\/api.php\" target=\"_blank\" rel=\"noreferrer noopener\">DirectAdmin API<\/a> to create user accounts, assign packages, assign IP addresses, and also create MySQL database, MySQL user, &amp; MySQL passwords for accounts automatically.<\/p>\n\n\n\n<p>If you don&#8217;t need to create the MySQL automatically, you can delete everything after the section <strong># MySQL Database details<\/strong><\/p>\n\n\n<p><span style=\"color: #ff0000;\"><strong>Parts you need to change:<\/strong><\/span><\/p>\n<p><strong># Constants<\/strong><\/p>\n<ol>\n<li><strong>DIRECTADMIN_HOSTNAME<\/strong><\/li>\n<li><strong>DIRECTADMIN_USERNAME<\/strong><\/li>\n<li><strong>DIRECTADMIN_PASSWORD<\/strong><\/li>\n<\/ol>\n<p><strong># Create the user account<\/strong><\/p>\n<ol>\n<li><strong>package=Package_Name<\/strong><\/li>\n<li><strong>ip=IP_A.D.D.R.E.S.S<\/strong><\/li>\n<\/ol>\n<h2 id=\"the-bash-script\" >The Bash Script<\/h2>\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#!\/bin\/bash\n\n# Constants\nDIRECTADMIN_HOSTNAME=&quot;your DA url&quot;\nDIRECTADMIN_PORT=2222\nDIRECTADMIN_USERNAME=&quot;your DA admin username&quot;\nDIRECTADMIN_PASSWORD=&quot;your DA admin password&quot;\nDIRECTADMIN_HTTPS=true  # Set this to true if your DirectAdmin server uses HTTPS\n\n# Command line arguments\nUSERNAME=&quot;$1&quot;\nPASSWORD=&quot;$2&quot;\nEMAIL=&quot;$3&quot;\nDOMAIN=&quot;$4&quot;\n\n# DirectAdmin API URL\nif [ &quot;$DIRECTADMIN_HTTPS&quot; = true ]; then\n  PROTOCOL=&quot;https&quot;\nelse\n  PROTOCOL=&quot;http&quot;\nfi\nAPI_URL=&quot;${PROTOCOL}:\/\/${DIRECTADMIN_HOSTNAME}:${DIRECTADMIN_PORT}\/CMD_API_ACCOUNT_USER&quot;\n\n# Create the user account\nRESPONSE=$(curl -s -u &quot;${DIRECTADMIN_USERNAME}:${DIRECTADMIN_PASSWORD}&quot; -d &quot;action=create&amp;add=Submit&amp;username=${USERNAME}&amp;email=${EMAIL}&amp;passwd=${PASSWORD}&amp;passwd2=${PASSWORD}&amp;domain=${DOMAIN}&amp;package=Package_Name&amp;ip=IP_A.D.D.R.E.S.S&amp;notify=no&quot; &quot;${API_URL}&quot;)\n\nif [[ $RESPONSE == *&quot;error=0&quot;* ]]; then\n  echo &quot;User account created successfully.&quot;\nelse\n  echo &quot;Error creating user account: $RESPONSE&quot;\nfi\n\n# MySQL Database details\nDB_NAME=&quot;$5&quot;\nDB_USER=&quot;$6&quot;\nDB_PASSWORD=&quot;$7&quot;\n\n# DirectAdmin API URL for MySQL database creation\nAPI_URL_DB=&quot;${PROTOCOL}:\/\/${DIRECTADMIN_HOSTNAME}:${DIRECTADMIN_PORT}\/CMD_API_DATABASES&quot;\n\n# Create the MySQL database\nRESPONSE_DB=$(curl -s -u &quot;${DIRECTADMIN_USERNAME}|${USERNAME}:${DIRECTADMIN_PASSWORD}&quot; -d &quot;action=create&amp;name=${DB_NAME}&amp;user=${DB_USER}&amp;passwd=${DB_PASSWORD}&amp;passwd2=${DB_PASSWORD}&quot; &quot;${API_URL_DB}&quot;)\n\nif [[ $RESPONSE_DB == *&quot;error=0&quot;* ]]; then\n  echo &quot;Database created successfully.&quot;\nelse\n  echo &quot;Error creating database. $RESPONSE_DB&quot;\nfi\n\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #616E88\">#!\/bin\/bash<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># Constants<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DIRECTADMIN_HOSTNAME<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">your DA url<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DIRECTADMIN_PORT<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #B48EAD\">2222<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DIRECTADMIN_USERNAME<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">your DA admin username<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DIRECTADMIN_PASSWORD<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">your DA admin password<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DIRECTADMIN_HTTPS<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #81A1C1\">true<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\"># Set this to true if your DirectAdmin server uses HTTPS<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># Command line arguments<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">USERNAME<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$1<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">PASSWORD<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$2<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">EMAIL<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$3<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DOMAIN<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$4<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># DirectAdmin API URL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$DIRECTADMIN_HTTPS<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">true<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">then<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">PROTOCOL<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">https<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">PROTOCOL<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">http<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">fi<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">API_URL<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">PROTOCOL<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">:\/\/<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_HOSTNAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">:<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_PORT<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">\/CMD_API_ACCOUNT_USER<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># Create the user account<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">RESPONSE<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">$(<\/span><span style=\"color: #88C0D0\">curl<\/span><span style=\"color: #A3BE8C\"> -s -u <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_USERNAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">:<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_PASSWORD<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\"> -d <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">action=create&amp;add=Submit&amp;username=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">USERNAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;email=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">EMAIL<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;passwd=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">PASSWORD<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;passwd2=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">PASSWORD<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;domain=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DOMAIN<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;package=Package_Name&amp;ip=IP_A.D.D.R.E.S.S\u00acify=no<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">API_URL<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #ECEFF4\">&quot;)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[[<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$RESPONSE<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">error=0<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">]]<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">then<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">User account created successfully.<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Error creating user account: <\/span><span style=\"color: #D8DEE9\">$RESPONSE<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">fi<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># MySQL Database details<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DB_NAME<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$5<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DB_USER<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$6<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">DB_PASSWORD<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9\">$7<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># DirectAdmin API URL for MySQL database creation<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">API_URL_DB<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">PROTOCOL<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">:\/\/<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_HOSTNAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">:<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_PORT<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">\/CMD_API_DATABASES<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #616E88\"># Create the MySQL database<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">RESPONSE_DB<\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #ECEFF4\">$(<\/span><span style=\"color: #88C0D0\">curl<\/span><span style=\"color: #A3BE8C\"> -s -u <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_USERNAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">|<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">USERNAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">:<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DIRECTADMIN_PASSWORD<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\"> -d <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">action=create&amp;name=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DB_NAME<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;user=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DB_USER<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;passwd=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DB_PASSWORD<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&amp;passwd2=<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">DB_PASSWORD<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #D8DEE9\">API_URL_DB<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #ECEFF4\">&quot;)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">if<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[[<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">$RESPONSE_DB<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">==<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">error=0<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #81A1C1\">*<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">]]<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">then<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Database created successfully.<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Error creating database. <\/span><span style=\"color: #D8DEE9\">$RESPONSE_DB<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">fi<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-use-the-script\" >How to use the script:<\/h2>\n\n\n\n<p>When you input the database name and database username, <strong>don&#8217;t include username_<\/strong>, this will be populated by the DirectAdmin API.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-usage\" >Example usage:<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\".\/create_user.sh [username] [password] [email] [domain] [mysqldatabase] [mysqluser] [db-password]\n\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">.\/create_user.sh<\/span><span style=\"color: #D8DEE9FF\"> [username] <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\">password<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\">email<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\">domain<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\">mysqldatabase<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\">mysqluser<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #D8DEE9FF\">db-password<\/span><span style=\"color: #ECEFF4\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 id=\"how-the-bash-script-works\" >How the bash script works.<\/h2>\n<p>Before running the script edit # Constants changing the server&#8217;s hostname, port number, your DirectAdmin username and password, and whether the server uses HTTPS.<\/p>\n<p>Run the script as command line arguments.<\/p>\n<p>Sends a request to the DirectAdmin API using the provided info to create the user account, including the username, email, password, domain, package name, IP address, and notification preferences.<\/p>\n<p>The script captures the API response.<\/p>\n<p>The script also allows creation of a MySQL database by providing the name, username, and password.<\/p>\n<p>Sends another request to the DirectAdmin API to create the database with provided information.<\/p>\n<h2 id=\"directadmin-all-about-api\" >DirectAdmin: All About API<\/h2>\n<p>DirectAdmin has a feature-set which allows you to control almost everything you can via a browser, but using socket based scripts instead. This is called an &#8220;API&#8221;.<\/p>\n<p>There are hundreds of possible API commands. Essentially, anything you can do normally in a browser, you can also do with the API. Just swap CMD_name to CMD_API_name (replace &#8220;name&#8221; with whatever the browser had), and use the same variables as the browser does running <a class=\"\" href=\"https:\/\/docs.directadmin.com\/directadmin\/general-usage\/troubleshooting-da-service.html#how-to-run-directadmin-in-debug-mode\" target=\"_blank\" rel=\"noopener\">directadmin in debug mode<\/a> ). Search for that CMD_API_name value in the <a href=\"http:\/\/www.directadmin.com\/search_versions.php?query=CMD_API\" target=\"_blank\" rel=\"noopener noreferrer\">Versions System<\/a><\/p>\n<p>for more information.<\/p>\n<p>Starting point and main API documentation:<br \/><a href=\"http:\/\/www.directadmin.com\/api.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.directadmin.com\/api.html<\/a><\/p>\n<p>Php communication class:<br \/><a href=\"http:\/\/forum.directadmin.com\/showthread.php?t=258\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/forum.directadmin.com\/showthread.php?t=258<\/a>Some API command are listed in the api.html page above, but most only exist in the versions system:<br \/><a href=\"http:\/\/www.directadmin.com\/search_versions.php?query=CMD_API\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.directadmin.com\/search_versions.php?query=CMD_API<\/a>More examples:<br \/><a href=\"http:\/\/www.directadmin.com\/sample_api.txt\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.directadmin.com\/sample_api.txt<\/a><br \/><a href=\"http:\/\/files.directadmin.com\/services\/all\/httpsocket\/examples\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/files.directadmin.com\/services\/all\/httpsocket\/examples\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here CainHosting has created a bash script to work with the DirectAdmin API to create user accounts, assign packages, assign IP addresses, and also create MySQL database, MySQL user, &amp; MySQL passwords for accounts automatically. If you don&#8217;t need to create the MySQL automatically, you can delete everything after the&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"ht-kb-category":[33],"ht-kb-tag":[43,40,44,39,29,41,42],"class_list":["post-215","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-directadmin","ht_kb_tag-automation","ht_kb_tag-bash","ht_kb_tag-create-user-account","ht_kb_tag-directadmin","ht_kb_tag-mysql","ht_kb_tag-ssh","ht_kb_tag-terminal"],"_links":{"self":[{"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/ht-kb\/215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":15,"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/ht-kb\/215\/revisions"}],"predecessor-version":[{"id":232,"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/ht-kb\/215\/revisions\/232"}],"wp:attachment":[{"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/ht-kb-category?post=215"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/cainhosting.com\/community\/wp-json\/wp\/v2\/ht-kb-tag?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}