From: Michael Heiming on 19 Jun 2006 17:31 In comp.os.linux.networking Ross <nospam(a)ross.com>: > "Bit Twister" <BitTwister(a)mouse-potato.com> wrote in message >> On Mon, 19 Jun 2006 16:42:01 -0400, Ross wrote: >>> Hi there, >>> I am going to create 9000 users. [ short bash script to do it ] >> http://tldp.org/LDP/abs/html/index.html > 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? Don't keep your files on a doze box, those can't even handle a text file probably, as you just encountered. Alternatively run 'dos2unix' over the file. Good luck BTW There's no need to create shadow + groups if you just use 'useradd' for the job. -- 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 223: The lines are all busy (busied out, that is -- why let them in to begin with?).
From: Chris F.A. Johnson on 19 Jun 2006 17:41 On 2006-06-19, Ross wrote: > > "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 [please don't top post] > 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 bash: CR=$'\r' user=${user%"$CR"} The script will be much faster in awk; see below. > 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. awk -v uid=1000 -v gid=999 ' NR % 1000 == 1 { ++gid } { sub( "\r","") printf "%s:x:%d:%d::/home/%s:/bin/bash\n", $1, ++uid, gid, $1 } ' userlist.txt >> /etc/passwd -- 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: Bit Twister on 19 Jun 2006 18:16 On Mon, 19 Jun 2006 17:19:33 -0400, Chris F.A. Johnson wrote: > You will also have to create a shadow file. Then there is creating home directory, copy initial user files from /etc/skel, set owner/group userX,...... :(
From: Bit Twister on 19 Jun 2006 18:22 On Mon, 19 Jun 2006 17:16:37 -0400, Ross wrote: > > 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. Use an if statement around the code bumping the group id to decide when to bump the group variable.
From: Chris F.A. Johnson on 19 Jun 2006 19:05 On 2006-06-19, Michael Heiming wrote: > In comp.os.linux.networking Ross <nospam(a)ross.com>: > >> "Bit Twister" <BitTwister(a)mouse-potato.com> wrote in message >>> On Mon, 19 Jun 2006 16:42:01 -0400, Ross wrote: >>>> Hi there, >>>> I am going to create 9000 users. > [ short bash script to do it ] > >>> http://tldp.org/LDP/abs/html/index.html > >> 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? > > Don't keep your files on a doze box, those can't even handle a > text file probably, s/probably/properly/ There is nothing improper about a Windows text file; the standard allows CR/LF line endings. > as you just encountered. Alternatively run > 'dos2unix' over the 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
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: dhcpd.conf setup Next: prism 2.5 chipset config. 4 ubuntu |