From: Ross on
Hi there,
I am going to create 9000 users.
I have all the user names in a txt file userlist.txt like this:
user_1
user_2
:
user_9000

I want the passwd file to be created like this:
user_1:x:1001:1000::/home/user_1:/bin/bash
user_2:x:1002:1000::/home/user_2:/bin/bash
:
user_1000:x:1001::/home/user_2000:/bin/bash
:
user_9000:x:1009::/home/user_9000:/bin/bash

How could I use bash with something like awk to create the passwd file?
And also the group, shadow files (all passwords can be the same)?
Thanks,
Ross


From: Bit Twister on
On Mon, 19 Jun 2006 16:42:01 -0400, Ross wrote:
> Hi there,
> I am going to create 9000 users.
> I have all the user names in a txt file userlist.txt like this:
> user_1
> user_2
>:
> user_9000
>
> I want the passwd file to be created like this:
> user_1:x:1001:1000::/home/user_1:/bin/bash
> user_2:x:1002:1000::/home/user_2:/bin/bash
>:
> user_1000:x:1001::/home/user_2000:/bin/bash
>:
> user_9000:x:1009::/home/user_9000:/bin/bash

looks like a simple while loop with two counters.

_uid=1000
_gid=999
while read user ; do
_uid=$(( $_uid + 1 ))
_gid=$(( $_gid + 1 ))
echo $user:x:$_uid:$_gid::/home/$user:/bin/bash >> /tmp/passwd
done < user_fn_here

for extra points
http://tldp.org/LDP/abs/html/index.html

From: Ross on
Thanks a lot for your idea!
But the $user comes with new line. The output is like this:
user_1^M:x:1001:1000::/home/user_1^M:/bin/bash
user_2^M:x:1002:1001::/home/user_2^M:/bin/bash
:

How could I eliminate the ^M?

In addition, I'd like to have users grouped like this: gid:1000 for users
user_1 to user_1000, and gid:1001 for users from user_1001 to user_2000,
etc.
Thanks again,
Ross

"Bit Twister" <BitTwister(a)mouse-potato.com> wrote in message
news:slrne9e3oo.bp7.BitTwister(a)wb.home.invalid...
> On Mon, 19 Jun 2006 16:42:01 -0400, Ross wrote:
>> Hi there,
>> I am going to create 9000 users.
>> I have all the user names in a txt file userlist.txt like this:
>> user_1
>> user_2
>>:
>> user_9000
>>
>> I want the passwd file to be created like this:
>> user_1:x:1001:1000::/home/user_1:/bin/bash
>> user_2:x:1002:1000::/home/user_2:/bin/bash
>>:
>> user_1000:x:1001::/home/user_2000:/bin/bash
>>:
>> user_9000:x:1009::/home/user_9000:/bin/bash
>
> looks like a simple while loop with two counters.
>
> _uid=1000
> _gid=999
> while read user ; do
> _uid=$(( $_uid + 1 ))
> _gid=$(( $_gid + 1 ))
> echo $user:x:$_uid:$_gid::/home/$user:/bin/bash >> /tmp/passwd
> done < user_fn_here
>
> for extra points
> http://tldp.org/LDP/abs/html/index.html
>


From: Chris F.A. Johnson on
On 2006-06-19, Ross wrote:
> Hi there,
> I am going to create 9000 users.
> I have all the user names in a txt file userlist.txt like this:
> user_1
> user_2
>:
> user_9000
>
> I want the passwd file to be created like this:
> user_1:x:1001:1000::/home/user_1:/bin/bash
> user_2:x:1002:1000::/home/user_2:/bin/bash
>:
> user_1000:x:1001::/home/user_2000:/bin/bash
>:
> user_9000:x:1009::/home/user_9000:/bin/bash
>
> How could I use bash with something like awk to create the passwd file?
> And also the group, shadow files (all passwords can be the same)?

awk -v gid=1000 '{ uid = gid + 1
printf "%s:x:%d:%d::/home/%s:/bin/bash\n", $1, uid, gid++, $1
}' userlist.txt >> /etc/passwd

You will also have to create a shadow file.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
From: Michael Heiming on
In comp.os.linux.networking Ross <nospam(a)ross.com>:
> Hi there,
> I am going to create 9000 users.
> I have all the user names in a txt file userlist.txt like this:
> user_1
> user_2
> :
> user_9000

> I want the passwd file to be created like this:
> user_1:x:1001:1000::/home/user_1:/bin/bash
> user_2:x:1002:1000::/home/user_2:/bin/bash
> :
> user_1000:x:1001::/home/user_2000:/bin/bash
> :
> user_9000:x:1009::/home/user_9000:/bin/bash

> How could I use bash with something like awk to create the passwd file?
> And also the group, shadow files (all passwords can be the same)?

awk 'BEGIN{u=1000}{u++;print $1":x:"u":1000::/home/"$1":/bin/sh"}' infile > out

But why the hassle? You can script useradd to do the job more
easily for you. As usual the fine manual 'man useradd' has the
info.

Good luck

BTW
Still curious what this has to do with networking?

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry(a)urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 182: endothermal recalibration