You are here
Home > Redhat > Add users using perl script in linux

Add users using perl script in linux

Create a file named user_file like this:

user001,pass001,/home/user001

user002,pass002,/home/user002
……..

Then running this script  the users will be created in /etc/shadow :

#!/usr/bin/perl

open(FILE1, "user_file");

$line=<FILE1>;

$salto='$1$ab34ef';

while($line ne "") {

chop($line);

@words=split(/,/, $line);

$my_pass=crypt(@words[1],$salto);

system("useradd -m -d @words[2] -p '$my_pass' @words[0]");

$line=<FILE1>;

}

close(FILE1);

Leave a Reply

2 + 3 =

Top