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.

Change password of WHM account based on CSV

Discussion in 'cPanel Developers' started by OOzypal, Mar 25, 2011.

  1. OOzypal

    OOzypal Registered

    Joined:
    Dec 5, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I have a CSV file like:

    01,xyz
    02,mux
    03,mysite
    04,mycarsite
    05,etcweb

    I would like to write a cood the read this csv file and replace the password of the account as such to have formula that contains the numbers above. For example

    01,xyz->mypassword01pad
    02,mux->mypassword02pad
    03,mysite->mypassword03pad
    04,mycarsite->mypassword04pad
    05,etcweb->mypassword05pad

    I tried my best and came up of the following:


    cpwd
    Code:
    #!/bin/bash
    INPUT=$1
    FORMULA=$2
    
    OLDIFS=$IFS
    IFS=,
    [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
    while read index acct
    do
    
           pw=`echo $FORMULA|sed "s/##/$index/g"`
           
          # passwd $acct $pw
          # Here I want to change each account with $pw
    
    done < $INPUT
    
    IFS=$OLDIFS
    The CSV File
    Code:
    01,john
    02,mike
    03,matt

    My optimum goal is to type


    Code:
    cpwd csv_filename formula
    Example
    Code:
    cpwd csv_filename de##g5@!*
    In this case the password for Matt will be
    Code:
    de03g5@!*
    No I am stuck in how to change the password in one line without prompting for password insertion.

    Thank you
     
  2. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    `echo $pw | passwd --stdin $acct`
     
  3. 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
    Hello OOzypal,

    I did want to provide some further information about the passwd command in root SSH. If you are only going to issue that command, you need to be aware that the FTP password and MySQL password for the main cPanel user will not be changed. The cPanel script that performs both passwd change for the cPanel user and the FTP cPanel user is the following:

    Code:
    /scripts/realchpass
    The cPanel script that changes the MySQL cPanel user password is the following:

    Code:
    /scripts/mysqlpasswd
    You may wish to take those scripts into consideration for the functionality you are trying to develop.

    Thanks!
     
Loading...

Share This Page