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.

Create multiple domain accounts with bash script

Discussion in 'cPanel Developers' started by Barrie Peterson, May 18, 2016.

  1. Barrie Peterson

    Barrie Peterson Registered

    Joined:
    May 18, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Hanmer Ontario
    cPanel Access Level:
    Root Administrator
    Hello

    I am trying to create multiple accounts with a bash script that works fine my issue is it reads the domain user-names and passwords form a file but /scripts/wwwacct is reading the file and trying to add everything as the domains even the user and pass. Bellow is a copy of the script and the file and the output when I run the script.

    Script
    Code:
    #! /bin/bash
    #make a file (/root/test1) which contains domain names, username and password.
    for i in `cat /root/test1`
    do
    domain=`echo $i | cut -f1 -d:`
    un=`echo $i | cut -f2 -d:`
    pw=`echo $i | cut -f3 -d:`
    /scripts/wwwacct $domain $un $pw 0
    done
    Domain, User, Pass File
    Code:
    domain.1 vname1 pass
    domain.2 vname2 pass
    domain.3 vname3 pass
    domain.4 vname4 pass
    domain.5 vname5 pass
    domain.6 vname6 pass
    domain.7 vname7 pass
    domain.8 vname8 pass
    domain.9 vname9 pass
    domain.10 vname10 pass
    domain.11 vname11 pass
    domain.12 vname12 pass
    domain.13 vname13 pass
    domain.14 vname14 pass
    domain.15 vname15 pass
    domain.16 vname16 pass
    domain.17 vname17 pass
    domain.18 vname18 pass
    domain.19 vname19 pass
    domain.20 vname20 pass
    domain.21 vname21 pass
    domain.22 vname22 pass
    domain.23 vname23 pass

    Any help to fix this would be great I know its how I have them listed in the file that is the issue so my question is how do I fix it so wwwacct can read it properly?
     
  2. Barrie Peterson

    Barrie Peterson Registered

    Joined:
    May 18, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Hanmer Ontario
    cPanel Access Level:
    Root Administrator
    Here is the output from the script, I forgot too add it.

    Output from script:
    Code:
    root@server [~]# ./test1
    +===================================+
    | New Account Info  |
    +===================================+
    | Domain: domain.1
    | UserName: domain.1
    | PassWord: domain.1
    +===================================+
    
    This ok?
    yes
    Checking input data......Done
    Validating system setup......Done
    Rebuilding IP Pool......Done
    Validating IP......Done
    Validating Username...(XID 27yssf) “domain.1” is not a valid username on this system.
    
    +===================================+
    | New Account Info  |
    +===================================+
    | Domain: vname1
    | UserName: vname1
    | PassWord: vname1
    +===================================+
    
    This ok? no
    Exiting on request!
     
  3. Znuff

    Znuff Member

    Joined:
    May 17, 2016
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Romania
    cPanel Access Level:
    DataCenter Provider
    echo "domain.1" | sed -e 's/\.//'
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,694
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    Is it necessary to store actual usernames and passwords in a text file on the system in plaintext? You may want to consider developing a script that randomly generates the username/password for an account rather than using one from a list, as an added security precaution.

    Thank you.
     
Loading...

Share This Page