Re: Adding a lot of users in a single operation.
The trouble is that none of the utilities (that I know of) allow you to specify the
password on the command line. Perhaps you can do it with pipes, like the following.
Ok, let's say you have a file users.txt with a list of user names you want to add, one
for i in $(cat users.txt) ; do pwd=$(makepasswd) ; echo $i $pwd >> userpass.txt ;
adduser --disabled-password --gecos $i $i ; cpwd=$(perl -e 'print crypt("'$pwd'",
"'$i'");') ; echo -e '/^'$i':/ s/:!:/:'$cpwd':/\nw\n' | ed /etc/passwd ; done
That should do it. (See, you had to user perl after all.) Mind you the above is all
one line, you'll have to fix the breaks inserted by my mail-reader and yours. Good
practice dictates you save your /etc/passwd file before completing the above. Also,
the above assumes you are not using shadow passwords. In any case the above should be
adaptable to shadow passwords too if you can see what I'm doing.
Jose L Gomez Dans wrote:
> I was wondering whether it would be possible to add a number of
> users with a single command. Ideally, there would be a call to pwgen (or
> something like that!) and the passwords would be held in a file.
> Any ideas (apart from "do it in perl!")?
> Jose L Gomez Dans PhD student
> Radar & Communications Group
> Department of Electronic Engineering
> University of Sheffield UK
> Unsubscribe? mail -s unsubscribe email@example.com < /dev/null
Jens B. Jorgensen