Hi 

What you say its should be pretty simple to do

1) First write a regex 

if input the file format is like below

uid123 , c50672216e6be50f327c7df719784fe3
uid567 , 31d3818ec221c94784c884b19d381bf3 

# below part of the code would give uid in $uid variable , $md5 would contain 
md5 hash

while(<>)
chomp;
/(.*),(.*)/;

my $uid=$1;
my $md5=$2;

# then write print statements according to your needs eg

print "dn: $uid,ou=student,dc=nits,dc=ac,dc=in\n";
print "uid: $uid\n";
print "cn: $uid\n";

and so on ...

then just run 

perl genLdif.pl in.txt > students.ldif

Here "in.txt" is the input file and "student.ldif" is the output file generate.

Hope this solves your problem, do let me know.

Regards,
Yash Vartak
Specialist, Distributed Systems and Services.
Neptune Orient Lines Ltd. 

Direct Tel: (+65) 6371 4483 | Direct Fax: (+65) 6371 4233 | E-mail: [EMAIL 
PROTECTED] | Website: http://www.nol.com.sg 
This message is intended for the recipient(s) named above.  It may contain 
confidential or privileged information.  If you are not the intended recipient, 
please notify the sender immediately by replying to this message and then 
delete it from your system.  Do not copy, use or circulate this communication.  
Thank you.

-----Original Message-----
From: Jyotishmaan Ray [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 19, 2008 5:28 PM
To: perl-ldap@perl.org
Subject: Need Help In Writing A Perl Script.

Dear All,

I am a new bie in perl. I have to generate LDIF files
after reading a file containing a list of userids of a new admitted
batch of a university along with their passwords, uidNUmber And
gidNumber. Say the new batch contains 400 students, and the uidNumber
starts from the number 2631 onwards. So for each new userid read from
the file (it contains the userids and their respective MD5 password), a
new LDIF file has to be generated. The LDIF file format for a student
is :-



dn: uid=s08-1-5-097,ou=student,dc=nits,dc=ac,dc=in
uid: s08-1-5-097
cn: s08-1-5-097
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$2P6e6UmE$ZewMWmNBQ0ghQ9l/OK0Ft/ 
loginShell: /bin/bash
uidNumber: 2631
gidNumber:
 2631
homeDirectory:
 /mnt/btech/s08-1-5-097
shadowLastChange:13458
shadowMin: 0
shadowMax: 999999
shadowWarning: 7



1) 
Here the lines which should be updated are the first line, where the
uid=uid=s08-1-5-097, is to be filled up for every new uid read from the
input file.

2)

The second line is to be updated with the uid read from the input file.

3)

The third line is to be updated with the uid for value of cn:



4)

Lines 4-7 are not to be changed for anything. They would remain same as shown 
above.

5)

The line 8's userPassword has to be updated after the MD5 passoword 
corresponding to each uid.

6)

Line 6 would remain same for all the files. Nothing to be changed.

7)

uidNumber and gidNumber would be same for a stundent and should be incremented 
for the nest
 file.


8)

The home directory should be as: /mnt/btech/value of uid

where the uid's value is read from the input file, for example it is 
here->s08-1-5-097

for all the files it would be different as uid is different for each student. 
This would be their home directory.

9) The lines below the line of homedirectory  would remain same for all the 
files.

Please provide me the perl script for that. I am just a new bie and would take 
weeks to write the script for doing that.

A sample student file of five  students is as given below (in the format of 
uid, MD5 password) as below:-



s08-1-5-093     $1$2P6e6UmE$X71iU1QF6it6oxalIPqMS/        
s08-1-5-094     $1$2P6e6UmE$R37ySEfe5JPjRTmdIo2xf.        
s08-1-5-095    
 $1$2P6e6UmE$VKlXe6lSoXr4aWBmuSn6u/        
s08-1-5-096    $1$2P6e6UmE$H7Q3Thg4KQKeuAvOsffp8.        
s08-1-5-097     $1$2P6e6UmE$ZewMWmNBQ0ghQ9l/OK0Ft/   


Now please generate five LDIF files in the format as shown above for each
uid after reading fro the input file of five students :-





Thanks,

Jmaan



      

Reply via email to