Find the answer to your Linux question:
Results 1 to 2 of 2
The is my program. #! /bin/bash clear echo Please enter your full name read fullname echo Please enter the user name you would like to use read username #print name ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Posts
    12

    Creatuser Program problem


    The is my program.

    #! /bin/bash

    clear

    echo Please enter your full name
    read fullname
    echo Please enter the user name you would like to use
    read username

    #print name and user name
    echo 'Name: ' $fullname
    echo 'User Name: ' $username

    #check for previous user IDs
    sort -n Users -o sort.out
    awk '{print $2}' sort.out > uid

    #create a user id
    x=`tail -1 uid `> z
    x=`cat z`
    uid=`expr $x + 1`

    #create home directory
    homedir=$username
    mkdir $homedir

    #add user line to password file (on this case using another filename instead of password)
    echo "$username:$uid:500:$fullname:$homedir:/bin/bash" >> Users

    #add user line to shadow file (on this case using another filename instead of shadow)
    echo "$username:$1$CzOIbYgv$zviWUTayJAzAn2J/eDXq30:13126:0:99999:7:::" >> shadow

    #change directory ownership and group membership
    chown $username $homedir
    chmod 700 $homedir
    chgrp 250 $homedir

    #assign password
    passwd $username

    #Print User names, User IDs, and home directories in alphabetical order (on this case using #another filename instead of password)
    sort newusers.txt | awk '{print $1 " "$3 " " $6}'

    #Count and print number of users
    wc newusers.txt | awk '{print "number of users: " $1}'


    This is the problem I'm getting

    Please enter your full name
    Steve
    Please enter user name
    steven
    name: steve
    username: steven
    chown: 'steven': invalid user
    passwd: unknow user steven
    number of uers: 0

    CAn't figure why its not creating the user. I have all the files the program needs.

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    First off, in the future, use the [code] tags to make code more readable.

    That said, why are you not using the useradd command? That would set the password, make the home directory, encrypt everything properly, set groups, etc. quite correctly.


    It seems to me that the user is never actually being added. My guess is that the environment needs to be updated to realize a new user exists.

    But yeah...look into the useradd command: "man useradd".

Posting Permissions

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