Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Auto creation of cpanel accounts through command line

Discussion in 'cPanel Developers' started by Arvand, Jun 12, 2012.

  1. Arvand

    Arvand Well-Known Member

    Jul 26, 2003
    Likes Received:
    Trophy Points:

    For the past year, we've had customer accounts and noc accounts created from within a cpanel VM automatically through a cron after the VM is provisioned (hyper-v). This worked up until 2 weeks ago when I went into our VM templates and upgraded all of their cPanels as well as the kernel. Now, all functions of the cron job work EXCEPT for the account creation. This is how the creation was being done -


    ## Create a new Account

    echo '#!/usr/bin/expect -f' > /root/expect
    echo "spawn /scripts/createacct "$DOMAIN" "$USERNAME" 12345678" >> /root/expect
    echo "expect ok?" >> /root/expect
    echo 'send "y\n"' >> /root/expect
    echo "interact" >> /root/expect
    chmod 755 /root/expect
    /root/expect &

    sleep 10

    This works if I just type in the commands in the VM. However, if it is being executed by a cron, it will not work (it used to).

    There is really no way for me to use the API unless I heavily modify our processes which would take a great deal of time. I really need to be able to create an account through command line. And support has told me there is no way but using the API which I find very hard to believe. A few years ago, there was an environment variable we could set so it wouldn't ask "This ok?" but that is no longer an option anymore.

    Anyone know of a work around.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst Staff Member

    Oct 2, 2010
    Likes Received:
    Trophy Points:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    You can pipe yes as that is a Linux command to any script that you run:

    yes | /scripts/createacct happytf 12346666
    If you do the above, it pipes yes when it runs and will create the user without having to input yes. Re-write your script to pipe yea like this and it should work. I just tested it and it doesn't even then ask me during the creation (I'm just pasting a small output as it creates the full account and goes on multiple lines afterward):

    # yes | /scripts/createacct happytf 12346666
    | New Account Info                  |
    | Domain:
    | UserName: happytf
    | PassWord: 12346666
    Checking input data......Done
    WWWAcct 12.5.0 (c) 2012 cPanel, Inc.......Done
    Running pre creation script (/usr/local/cpanel/scripts/prewwwacct)......Done
    Adding User......Done
    Copying skel files from /root/cpanel3-skel/ to /home/happytf/......Done
    Adding Entries to httpd.conf......Done
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice