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 ?
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/
/mnt/btech/rollno
--- On Tue, 8/19/08, Jason A. Kates <ja...@kates.org> wrote:
--- 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
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
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
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
============================================================================
> 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.
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
Thanks in advance, jm
thanks
jack
-----Original Message-----
From: Jyotishmaan Ray [mailto:jyoti...@yahoo.com]