I  would need it in a different server to create all the home directories.



Kindly provide a different script for that. 



  

--- On Tue, 8/19/08, Anirban Adhikary <[EMAIL PROTECTED]> wrote:
From: Anirban Adhikary <[EMAIL PROTECTED]>
Subject: Re: Script neeed for creating home directories for each student!!
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Date: Tuesday, August 19, 2008, 7:01 PM

You can do one thing 
you just add the following lines at end of the while  loop like this The lines 
in bold character are newly added And one more thing when u will creating the 
home directory of the users then u have the write ownership on /mnt/btech 
directory.


Regards
Anirban Adhikary.


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+/,$_);
    my $homedir = "/mnt/btech/$a";
    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\n";
    print FH1 "uidNumber: $uidNumber\n";
    print FH1 "gidNumber: $gidNumber\n";
    print FH1 "homeDirectory: $homedir\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;
      `mkdir "$homedir"; chmod 700 "$homedir";` if(! -e $homedir);
 }
close(FH);
close(FH1);

another way is do the home directory creating job in another script

use strict;
use warnings;
open(FH,"/home/anadhikary/perl/sourcefile");
while(<FH>)
{
    ($a,$b)=split(/\s+/,$_);

     my $homedir = "/mnt/btech/$a";
    `mkdir "$homedir"; chmod 700 "$homedir";` if(! -e $homedir);
     
 }
 
close(FH);

 


On Tue, Aug 19, 2008 at 6:29 PM, Jyotishmaan Ray <[EMAIL PROTECTED]> wrote:





Thank you Anirban.



Also do you any script for creating the home directories in a server
machine for 424 students in the path :  

/mnt/btech/uid, where uid =
s08-1-5-097 for the same file read, as before.

All the students must have all permissions to read, write and execute in their 
home directories.


 Can  you send me that. I am
also trying. In the earlier case, i had just done to the point of file
reading and writing. 



It was amazingly written.



  

--- On Tue, 8/19/08, Anirban Adhikary <[EMAIL PROTECTED]> wrote:


From: Anirban Adhikary <[EMAIL PROTECTED]>


Subject: Re: Perl Script Needed Urgently.!!
To: beginners@perl.org
Date: Tuesday, August 19, 2008, 3:18 PM

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/
u



      




      

Reply via email to