The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto creation of cpanel accounts through command line

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

  1. Arvand

    Arvand Well-Known Member
    PartnerNOC

    Joined:
    Jul 26, 2003
    Messages:
    130
    Likes Received:
    1
    Trophy Points:
    18
    Hello,

    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 -

    USERNAME=$USERNAME
    DOMAIN=$DOMAIN

    ## 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.
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    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:

    Code:
    yes | /scripts/createacct happytime.foo 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):

    Code:
    # yes | /scripts/createacct happytime.foo happytf 12346666
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: happytime.foo
    | 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
     
Loading...

Share This Page