<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thank you<br>
<br>
<br>
<br>
<br>
On 02/25/2011 01:02 PM, Mike Miller wrote:
<blockquote
cite="mid:alpine.DEB.2.00.1102251158530.26842@taxa.psych.umn.edu"
type="cite">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)...
<br>
<br>
<br>
On Fri, 25 Feb 2011, Raymond Norton wrote:
<br>
<br>
<blockquote type="cite">Here is a sample of the list (yes, it came
from a record the tech was keeping of email passwords).
<br>
<br>
fiecke,04f13cke
<br>
heiraas,2qasw#
<br>
ed houg,6$I$Tr$8
<br>
johnson,j0hns0n
<br>
kallenbach,RC68!
<br>
crd klobe,jmc1862
<br>
kramer,r2bydoo1
<br>
</blockquote>
<br>
<br>
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.
<br>
<br>
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:
<br>
<br>
chmod 755 password_encrypt.pl
<br>
<br>
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:
<br>
<br>
(1) first test that the file format is correct:
<br>
<br>
awk -F',' '{print NF}' users.txt | uniq | wc -l
<br>
<br>
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.
<br>
<br>
(2) next, if you passed test 1, test that the usernames are
unique:
<br>
<br>
cut -d',' -f1 users.txt | tr ' ' '_' | sort | uniq -c | awk
'{print $1}' | sort -n | tail -1
<br>
<br>
That also should produce "1" as output. If you get a number
greater than one, then not all of your usernames are unique.
<br>
<br>
(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:
<br>
<br>
( cut -d',' -f1 users.txt | tr ' ' '_' ; cut -d':' -f1 /etc/passwd
) | sort | uniq -c | awk '{print $1}' | sort -n | tail -1
<br>
<br>
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.
<br>
<br>
(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
<a class="moz-txt-link-rfc2396E" href="mailto:email@external.site"><email@external.site></a>".
<br>
<br>
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:
<br>
<br>
echo -e "#!/bin/bash\n" > make_users.bash
<br>
chmod 700 make_users.bash
<br>
<br>
<br>
NOT DONE YET...
<br>
<br>
awk -F',' '{print "useradd -u "1000+NR" -g 100 -s /bin/bash -p
$(password_encrypt.pl \042"
<br>
$2"
<br>
PASSWORD SALT) USERNAME
<br>
<br>
#' users.txt >> make_users.bash
<br>
<br>
Read the script, and if it looks good, run this:
<br>
<br>
sudo ./make_users.bash
<br>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
<a class="moz-txt-link-abbreviated" href="mailto:tclug-list@mn-linux.org">tclug-list@mn-linux.org</a>
<a class="moz-txt-link-freetext" href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list">http://mailman.mn-linux.org/mailman/listinfo/tclug-list</a>
</pre>
</blockquote>
</body>
</html>