Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl Script Needed To Create The Home Drectories.

25 views
Skip to first unread message

Jyotishmaan Ray

unread,
Aug 19, 2008, 12:46:13 PM8/19/08
to perl...@perl.org

Dear All,

I am a new bie in perl. I have to create the home directories of 424 students in a server machine.

The path of the home directory would be :-

/mnt/btech/formatted-rollno.

where formatted-rollno ="s08-1-5-097"


And the input file contains all the rollnos of 424 students.

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

s08-1-5-093    
s08-1-5-094    
s08-1-5-095     
s08-1-5-096          
s08-1-5-097    

For example, the home directories,  for the rollno, s08-1-5-097, would be this->


 /mnt/btech/s08-1-5-097

All the student should have read/write and execute permissions in their home directories.


Can any one provide the perl script  for doing this ?

  


Peter Karman

unread,
Aug 19, 2008, 1:16:42 PM8/19/08
to jyoti...@yahoo.com, perl...@perl.org


look at the Path::Class module on CPAN. Should make it easy.

use strict; # always
use Path::Class;
my $base = '/mnt/btech';
foreach my $rollno (@get_my_list_of_rollnos) {

my $path = dir( $base, $rollno );
$path->mkpath(1);
chown $path, $rollno or die "can't chown $path $rollno: $!";
# ^^ probably needs to run as root to work

}

and next time, ask on the right list for this kind of thing. This is not an LDAP question.

--
Peter Karman . pe...@peknet.com . http://peknet.com/

Jyotishmaan Ray

unread,
Aug 19, 2008, 1:32:12 PM8/19/08
to Jason A. Kates, perl...@perl.org
Is that possible to create the home directories-

/mnt/btech/rollno


  

--- On Tue, 8/19/08, Jason A. Kates <ja...@kates.org> wrote:


Jyotishmaan Ray

unread,
Aug 19, 2008, 1:35:01 PM8/19/08
to perl...@perl.org, Peter Karman
Your script is not clear. Please provide step wise solution. I am a new bie in perl.

 

--- On Tue, 8/19/08, Peter Karman <pe...@peknet.com> wrote:
From: Peter Karman <pe...@peknet.com>
Subject: Re: Perl Script Needed To Create The Home Drectories.
To: jyoti...@yahoo.com, "perl...@perl.org" <perl...@perl.org>
Date: Tuesday, August 19, 2008, 10:46 PM

Yash V Vartak

unread,
Aug 19, 2008, 10:20:42 PM8/19/08
to jyoti...@yahoo.com, perl...@perl.org, Peter Karman
Ray,

You should not expect the community to write entire stuff for you, the community is for programmers to help each other with genuine queries, and not give ready made solutions.

No one learns to code over night! It needs hrs of patient efforts, and you ll have to work for yourself.

Being a new bee you should have a look at following sites they have all the information you need w.r.t the project you are working

http://search.cpan.org/~gbarr/perl-ldap-0.33/lib/Net/LDAP.pod

http://www.lc.leidenuniv.nl/awcourse/oracle/network.920/a96579/comtools.htm#632173

http://quark.humbug.org.au/publications/ldap/ldap_tut.html

http://www.faqs.org/rfcs/rfc2849.html (LDIF RFC)

http://www.tizag.com/perlT/perlstrings.php (printing of LDIF)

The above site have all the info you need, now ..be a good boy and do it yourself. :)

Regards,
Yash

Marc Girod

unread,
Aug 20, 2008, 3:35:04 AM8/20/08
to Vartak, Yash V, jyoti...@yahoo.com, perl...@perl.org, Peter Karman
Hi all,

May I add my grain of salt?

On Wed, Aug 20, 2008 at 3:20 AM, Vartak, Yash V <Yash_...@apl.com> wrote:

> You should not expect the community to write entire stuff for you,
> the community is for programmers to help each other with genuine queries,
> and not give ready made solutions.

Granted.

> No one learns to code over night! It needs hrs of patient efforts, and you ll have to work for yourself.

Sure.

> Being a new bee you should have a look at following sites they have all the information you need w.r.t the project you are working

It strikes me that this reply shares with the question what I would
reproach it most: its top-down approach.

I never learned to program.
I programmed solutions to my problems at hand.
Nothing else I can really claim.

So the question 'it is not clear, provide a stepwise solution'
is non-receivable.
But, questions like 'why is there a @ on line 4?' should be
acceptable.

Marc

Jyotishmaan Ray

unread,
Aug 20, 2008, 3:45:14 AM8/20/08
to perl...@perl.org, Peter Karman, Vartak, Yash V
Would appreciate you if provide some pointers in writing a script for
creating some hundreds of home directories for each one of them.


Jason A. Kates

unread,
Aug 19, 2008, 1:26:58 PM8/19/08
to jyoti...@yahoo.com, perl...@perl.org
Instead of creating the home directory as part of a batch job you might
think of having the OS take care of it only when required.

Under linux you might think of updating
/etc/pam.d/system-auth and add this line:
session required pam_mkhomedir.so skel=/etc/skel/ umask=0022

The users home directory will get created on the 1st login.
-Jason

--
----------------------------------------------------------------------------
Jason A. Kates (ja...@kates.org)
Fax: 208-975-1514
Phone: 212-400-1670 x2
============================================================================


Andrej Ricnik-Bay

unread,
Aug 20, 2008, 2:03:20 PM8/20/08
to Marc Girod, Perl-LDAP Mailing List
On 20/08/2008, Marc Girod <marc....@gmail.com> wrote:

> But, questions like 'why is there a @ on line 4?' should be
> acceptable.

But you don't sign up for a power-sliding event and then
ask the people there what those pedals are for ... ?


> Marc
Cheers,
Andrej


--
Please don't top post, and don't use HTML e-Mail :} Make your quotes concise.

http://www.american.edu/econ/notes/htmlmail.htm

Brian Reichert

unread,
Aug 20, 2008, 4:54:07 PM8/20/08
to Jyotishmaan Ray, Marc Girod, Perl-LDAP Mailing List, Andrej Ricnik-Bay, begi...@perl.org
On Wed, Aug 20, 2008 at 12:07:02PM -0700, Jyotishmaan Ray wrote:
>

Depending on the Linux system's policies, executing a command like this:

useradd -m -d /mnt/btech -c $encrypted_password -s $shell $user

will:

- create the UID in the password database
- create a group ID in /etc/groups
- add that password to the password database
- create the user's home directory
- cause said directory to be owned by that new UID and GID
- populate that directory with any template for .bashrc, etc. as
are configured in /etc/skel

Read the manpage for the command your OS is using. These commands
come with other arguments to manage auxiliary groups, nonstandard
home directory locations, etc.

Check for errors on each invokation; any of the above actions may
have failed for any reason.

If you want to make use of the specific UIDs and GIDs in the LDAP
data, you'll have to mess with adding groups, etc. more manually.
See groupadd(8).

If you want to preserve the password aging data, that gets more
tricky, but is still doable; see chage(1).

This is not an LDAP question.

This is not a perl question.

There are many forums that document this, and there are many
Googleable (is that a verb?) instances of

perl "add user"

out there, many using LDAP as a source of users.

There are consultants out there who'll do this work for pay, if you
feel you're in over your head.

Good luck!

--
Brian Reichert <reic...@numachi.com>
55 Crystal Ave. #286 Daytime number: (603) 434-6842
Derry NH 03038-1725 USA BSD admin/developer at large

Jyotishmaan Ray

unread,
Jan 4, 2009, 11:36:22 PM1/4/09
to perl...@perl.org
Dear All,
 
I am a new bie in perl scripting language.
 
I have this problem :
 
I have around 500 students directories created on a server where they (students) have their own program files etc.
 
Now the priblem is to delete all these files of those students whose roll no. starts with
 
 s08-1-**-*
 
where
the ** means a number between 1 and 5 (inclusive ) specifying the branch they study in
 the * means the a number between 0 and 100 or more
 
or
 
can be done this way too considering the rollno as s08-1-1-**
 
where ** stands for the students regsitration number/roll number.
 
In that case the script will have to  be changed for each branch, by changing the number 1, 2, 3,,4 0r 5.
 
Ultimately we have to delete all the files stored in these folders without deleting their home directories.
 
Can any one give a nice script/ solution  to do this.
 
 

Thanks in advance, jm


     

John Sheahan

unread,
Jan 5, 2009, 9:54:36 AM1/5/09
to jyoti...@yahoo.com, perl...@perl.org
what is the exact path to the directories? can you give me a few examples?

thanks

jack

-----Original Message-----
From: Jyotishmaan Ray [mailto:jyoti...@yahoo.com]

0 new messages