[95577] in RedHat Linux List

home help back first fref pref prev next nref lref last post

Re: Adding Users

daemon@ATHENA.MIT.EDU (Kevin Smith)
Mon Oct 19 13:44:19 1998

Date: Mon, 19 Oct 1998 12:46:45 -0500 (CDT)
From: Kevin Smith <kevin@mtsu.edu>
To: redhat-list@redhat.com
In-Reply-To: <19981019153546.2662.rocketmail@send101.yahoomail.com>
Resent-From: redhat-list@redhat.com
Reply-To: redhat-list@redhat.com

On Mon, 19 Oct 1998, Kade Cole wrote:

> I was wondering if anybody knew of a way to add multiple users to a
> redhat 5.1 systems via a text file. I have a file that contains
> username/passwords and I wish to run the adduser/useradd program to
> add all the users from the text file with the appropriate
> names/passwords. Please help if you can. Thanks for any help.

Assuming the files are int he format of "login:password"
the following perl script should do the job

-- cut --
#!/usr/bin/perl

my $seed = rand(time|$$);
srand($seed);

my @chars=qw( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
              a b c d e f g h i j k l m n o p q r s t u v w x y z
              0 1 2 3 4 5 6 7 8 9 );

my $filename = shift || die "Usage: adduser.pl <filename>\n\n";

open(MYIN,"<$filename") or die "Error opening file: $!\n\n";

foreach $line (<MYIN>) {
    ($login,$pass)=split(/:/,$line);
    my $salt = $chars[int(rand(62)+.5)] . $chars[int(rand(62)+.5)];
    $encPass=crypt($pass,$salt);
    `/usr/sbin/useradd -p $encPass $login`;
}

close(MYIN);
-- cut --

bleh.. probably a little more complicated than what is needed.. but
it will work nevertheless... :)

-----
Kevin Smith
kevin@mtsu.edu

We are not a loved organization, but we are a respected one.
		-- John Fisher


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
		http://www.redhat.com http://archive.redhat.com
         To unsubscribe: mail redhat-list-request@redhat.com with 
                       "unsubscribe" as the Subject.


home help back first fref pref prev next nref lref last post