Results 1 to 5 of 5

Thread: useradd script

  1. #1

    Default useradd script

    Hallo all

    I was trying to make a useradd end userdell script.
    Now i found this site
    Create Users And Change Passwords With A Bash Script | HowtoForge - Linux Howtos and Tutorials

    And i did what the sad and the useradd, userdel and pass scripts work.
    Dis is what i have
    a list with users saved a userlist.txt

    uderadd script:
    #!/bin/sh
    for i in `more userlist.txt `
    do
    echo $i
    useradd $i
    done

    Then i type in the terminal ./useradd.txt
    Then the users are added.
    then i have a password script:
    #!/bin/sh
    for i in `more userlist.txt `
    do
    echo $i
    echo $i"123" | passwd "$i" --stdin
    echo; echo "User $username's password changed!"
    done

    then the user has his name with 123 as password.
    Now in the comment function on the site some one posted a script like this:
    #!/bin/sh
    for i in `more userlist.txt `
    do
    echo $i
    echo $i | change -d 0 "$i"
    echo; echo "User $i will be forced to change password on next login!"
    done

    then users had to change there password when the log in the first time.
    And i tried that script but then i get this massage:
    nurealam
    ./pass1.txt: line 5: change: command not found

    Now my question is what is wrong with that script ?
    All other scripts work fine.


    Userdel script i have:

    #!/bin/sh
    for i in `more userlist.txt `
    do
    echo $i
    userdel -r $i
    done


    Greet Davano

  2. #2

    Default Re: useradd script

    Hello Davano,

    First of all next time you post code/output please put it in code tags.
    Posting in Code Tags - A Guide

    Quote Originally Posted by Davano
    then users had to change there password when the log in the first time.
    And i tried that script but then i get this massage:
    nurealam
    ./pass1.txt: line 5: change: command not found

    Now my question is what is wrong with that script ?
    All other scripts work fine.
    The command isn't change but chage.
    More information about the chage command here: chage

    Good luck!
    Where did I put my coffee cup?
    dir -R /home/* | grep "coffee cup"

  3. #3

    Default Re: useradd script

    Thx for the reply.

    And sorry will post it in code tags next time.

    I now changed it to chage and now it works.
    When i log in with the user i need to change the password.
    But it wont log in because there is now home folder.
    i get the massage:
    Code:
    Cannot enter home directory. Using /.
    When i look in the directory the home folders are not there.

    Can the code be changed so that is greats the home folders to ?
    If so what do i need to change in the code ?

    Greet Davano

  4. #4
    Join Date
    Aug 2008
    Location
    Behind the 8 ball
    Posts
    116

    Default Re: useradd script

    Pass the -m option to the useradd command

    Code:
    #!/bin/sh
    for i in `more userlist.txt `
    do
       echo $i
       useradd -m $i
    done
    For more information about the useradd command type
    Code:
    man useradd
    Good luck,
    Hiatt

  5. #5

    Default Re: useradd script

    Thx for the reply.

    Dint no i can just add the useradd options.
    I already played with the options in the terminal.
    So then i will go and play around with the useradd options in the script.

    Again thanks all for the help.

    Greets Davano

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •