home       inleiding       sysadmin       services       links       bash       werk       nothing      

create users from a list via script

 

  1. script
     
    user@cassandra ~/bin $ cat museradd.sh
    #!/bin/bash
    # ***********************
    # museradd v0.0 16/01/018
    # ***********************
    # moet gebruikt worden met sudo
    #
    # om multiple users aan te maken met bvb 2 x sdf12345 in passwfile
    #             users in userfile
    ##################################
    while read gebruiker
    do
    echo $gebruiker
    useradd -m $gebruiker
    passwd $gebruiker < passwdfile
    done < userfile

     

  2. files
     
    Create two textfiles:
    userfile contains a list of users (one per line)
    passwdfile contains a default password (twice because passwd needs it twice)
     
    user@cassandra ~ $ cat userfile
    yoren
    waldo
    gunther
    lynn
    sarah

     
    user@cassandra ~ $ cat passwdfile

    qwerty123
    qwerty132

     

  3. parameters
     
    should be modified to use parameters for userfile and passwdfile