Hi Jyotishmaan Ray
U can do the task in the following way but there may be some other good and
compact way.
The source file is the file where uid and user password are written but one
thing in the source file u need to keep uid and user passwd in the same
line. like this
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/
AND the code is as follows
use strict;
use warnings;
my($a,$b);
my $uidNumber=2631;
my $gidNumber=2631;
open(FH,"/home/anadhikary/perl/sourcefile");
open(FH1,">>/home/anadhikary/perl/destinationfile");
while(<FH>)
{
($a,$b)=split(/\s+/,$_);
print FH1 "\n";
print FH1 "dn: uid=$a,ou=student,dc=nits,dc=ac,dc=in\n";
print FH1 "uid: $a\n";
print FH1 "cn: $a\n";
print FH1 "objectClass: account\n";
print FH1 "objectClass: posixAccount\n";
print FH1 "objectClass: top\n";
print FH1 "objectClass: shadowAccount\n";
print FH1 "userPassword: {crypt}$b\n";
print FH1 "loginShell: /bin/bash/$a\n";
print FH1 "uidNumber: $uidNumber\n";
print FH1 "gidNumber: $gidNumber\n";
print FH1 "homeDirectory: /mnt/btech/$a\n";
print FH1 "shadowLastChange:13458\n";
print FH1 "shadowMin: 0\n";
print FH1 "shadowMax: 999999\n";
print FH1 "shadowWarning: 7\n";
$uidNumber +=1;
$gidNumber +=1;
}
close(FH);
close(FH1);
On Tue, Aug 19, 2008 at 1:17 PM, Jyotishmaan Ray <[EMAIL PROTECTED]>wrote:
>
> 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 redaing fro the input file of five students :-
>
>
>
>
>