Just saw that you already did it. I'll try to finish this later, but for
now it has some possibly useful info (e.g., attached script)...
On Fri, 25 Feb 2011, Raymond Norton wrote:
> Here is a sample of the list (yes, it came from a record the tech was keeping of email passwords).
>
> fiecke,04f13cke
> heiraas,2qasw#
> ed houg,6$I$Tr$8
> johnson,j0hns0n
> kallenbach,RC68!
> crd klobe,jmc1862
> kramer,r2bydoo1
I'll just mention up front that I prefer tab-delimited files to
comma-delimited files for this purpose and for most other purposes. I
also think you would be much better off with more data (like real names
for users) -- see below my comment on comments.
See the attached script for dealing with the passwords. The useradd
program (recommended by someone else in this thread) requires that the
password be entered as an encrypted string, not the original password.
The attached perl script will be used to encrypt the password. Save it in
your path and make it executable:
chmod 755 password_encrypt.pl
Suppose your list is stored in the file users.txt and suppose there is
exactly one comma on every line and the usernames are to be the string son
the left of the comma, but with spaces replaced by underscores, then you
could do this:
(1) first test that the file format is correct:
awk -F',' '{print NF}' users.txt | uniq | wc -l
That should produce "1" as output, if the output is not "1" then your file
has too many commas on one or more lines, probably because you have a
password with a comma in it.
(2) next, if you passed test 1, test that the usernames are unique:
cut -d',' -f1 users.txt | tr ' ' '_' | sort | uniq -c | awk '{print $1}' | sort -n | tail -1
That also should produce "1" as output. If you get a number greater than
one, then not all of your usernames are unique.
(3) if you passed tests 1 and 2, you also want to know that the usernames
you are adding are not identical to any that already exist in
/etc/password, so do this:
( cut -d',' -f1 users.txt | tr ' ' '_' ; cut -d':' -f1 /etc/passwd ) | sort | uniq -c | awk '{print $1}' | sort -n | tail -1
That also should produce "1" as output. If you get a number greater than
one, then at least one of your new usernames is identical to one already
in /etc/passwd.
(4) If you passed tests 1 through 3, then you'll want to transform the
users.txt file into a little script for adding the users. It would be
better if you had more information for the comment field -- like their
actual names -- but you do what you can with what you've got. I like a
comment that contains "First Last <email at external.site>".
You need to choose a group ID and an initial user ID, maybe "1000" we can
then make the nth user have UID equal to initial_UID+n. I'll hardcode
that initial UID number as 1000 here, and I'll hardcode the GID as 100,
but you can change them:
echo -e "#!/bin/bash\n" > make_users.bash
chmod 700 make_users.bash
NOT DONE YET...
awk -F',' '{print "useradd -u "1000+NR" -g 100 -s /bin/bash -p $(password_encrypt.pl \042"
$2"
PASSWORD SALT) USERNAME
#' users.txt >> make_users.bash
Read the script, and if it looks good, run this:
sudo ./make_users.bash
-------------- next part --------------
A non-text attachment was scrubbed...
Name: password_encrypt.pl
Type: text/x-perl
Size: 669 bytes
Desc:
URL: <http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20110225/28e3c743/attachment.pl>