[techtalk] massadd

Brian Sweeney bsweeney at mail.veinc.com
Fri Jun 16 11:43:13 EST 2000


Hey all-
Thanks for everyone's help with the mass user add problem!  I have two
possible solutions I'm suggesting for the FAQ.

One is to use the pdadduser package, available at
http://ghs.ssd.k12.wa.us/~pdavis/projects/pdadduser.html.
If you've got the time to learn the syntax, this is my suggestion.  However,
I found this after I had already written the following perl script, that
does what I needed it to do.  Feel free to use it to your heart's content,
if you find it useful.  It requires you to have perl (obviously) and Expect
installed with the autopasswd Expect script in your /usr/bin directory.  Get
more info on Expect (a really neat language/tool for automating processes)
at http://expect.nist.gov. It's only been tested, however, on my system
running RHL 6.0, but it's pretty standard stuff, so I'm not too concerned
that it wouldn't be portable.  Well, here it is...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl
#
# NAME: massadd
# DESCRIPTION:  Perl script to add users from a file and assign them
# 		passwords from another file
#
# Created 6/15/00 by Brian J. Sweeney
# email: bsweeney at angelfire.com
#
# PRE: Two files required, user_file of usernames and pass_file of
passwords.
#      Both files have the same format, one item per line.
#
# POST: All users in user_file created with corresponding passwords in
#	pass_file.
#
# NOTE: The first user in the user_file is given the
#	first password in the pass_file.  Make sure you have the same number
#	of usernames and passwords! Also, notice this script has no bells and
#	whistles, no checks to make sure the user is doing what they're
#	supposed to.  It's not too robust.
#
# REQ:  The expect language, and the autopasswd expect script.  This is
#	available at http://expect.nist.gov.  NOTE FOR RHL USERS: YOU MUST
#	INSERT THE COMMAND "sleep 1" BETWEEN THE LINES "expect("password:")"
#	AND "send("password\r")" IN THE AUTOPASSWD EXPECT SCRIPT
#	BECAUSE OF A BUG IN THE PASSWD COMMAND. This script assumes your
#	useradd command is in /usr/sbin, and your autopasswd script is in
#	/usr/bin.  It also (obviously) requires perl!
#
# Like everything else in the world, this script comes with no guarantees!
# I am not responsible if somehow it manages to destroy your computer and/or
slay your dog, or
# does anything else you didn't want it too!  Also, be sure to DESTROY THE
PASSWORD FILE
# after you use this script, otherwise it's a HUGE security hole!



$count=0;
if (open(NAME_FILE,"user_file")){
	@user_names = <NAME_FILE>;
	chop (@user_names);
	print ("Names opened\n");
}
if (open(PASS_FILE, "pass_file")){
	@passwords = <PASS_FILE>;
	chop (@passwords);
	print ("Passwords opened\n");
}
close (NAME_FILE);
close (PASS_FILE);
foreach $user (@user_names) {
	$pass = @passwords[$count];
	print("$count\n");
	print("$user\n");
	print("$pass\n");
	system("/usr/sbin/useradd $user");
	system("/usr/bin/autopasswd $user $pass");
	print("User $user created with password $pass! \n");
	$count++;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






More information about the Techtalk mailing list