Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, Our requirement is to create multiple user account with UID:- /tmp/users.txt rohit guna samsir like this 100 user names in /tmp/users.txt file /tmp/uid.txt 2001 3789 1000134 like this 100 ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    13

    Useradd Script

    Hi,

    Our requirement is to create multiple user account with UID:-

    /tmp/users.txt

    rohit
    guna
    samsir

    like this 100 user names in /tmp/users.txt file

    /tmp/uid.txt

    2001
    3789
    1000134

    like this 100 UID's in /tmp/UID.txt file

    The script should take input from both the files and create user account. for example user account rohit should have an UID of 2001 and user samsir should have an UID of 1000134. How to achieve this, your help would be highly appreciated. I need to create 100 user account like this.

  2. #2
    Just Joined! crayfishuk's Avatar
    Join Date
    Mar 2011
    Location
    London
    Posts
    5
    Quote Originally Posted by purusrhce View Post
    Hi,

    The script should take input from both the files and create user account. for example user account rohit should have an UID of 2001 and user samsir should have an UID of 1000134. How to achieve this, your help would be highly appreciated. I need to create 100 user account like this.
    Theres a hundred ways you could do it, heres one...



    #!/bin/bash

    count=`wc -l users.txt | awk '{print $1}'`

    for n in `seq 1 $count`; do
    username=`awk "FNR == $n" users.txt`
    uid=`awk "FNR == $n" uids.txt`
    /usr/sbin/useradd -m -u $uid -s /bin/bash $username
    done

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    13
    Quote Originally Posted by crayfishuk View Post
    Theres a hundred ways you could do it, heres one...



    #!/bin/bash

    count=`wc -l users.txt | awk '{print $1}'`

    for n in `seq 1 $count`; do
    username=`awk "FNR == $n" users.txt`
    uid=`awk "FNR == $n" uids.txt`
    /usr/sbin/useradd -m -u $uid -s /bin/bash $username
    done
    Excellent it works fine, Thank you very much

Posting Permissions

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